Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Inheritance problem with Id in subclass
Inheritance problem with Id in subclass [message #485541] Sat, 12 September 2009 19:17 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 92
Registered: July 2009
Member
Hello

I have quite a problem with my inheritance. According to the documentation I
dont need a id column in the subclass, but when I start my EntityManager, it
always wants an Id for it.
Here is what I did

Person:

@Entity @Table(name="Persons")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TYPE")
public class Person {

@Id
@GeneratedValue
protected int id;
@Column(nullable = false)
protected String firstName;
@Column(nullable = false)
protected String lastName;

Customer:

@Entity @Table(name = "Customers")
@DiscriminatorValue("C")
public class Customer extends Person {

//no id needed here


I tried all things that came in my mind: macking the id-attribute protected so
the subclass can see it (but in tutorials nobody does that), and I tried to make
the parent abstract. But none of these helped. EclipseLink still complains that
my Customer-class has no primary key with @Id.
I also thought that my persistence.xml is wrong so I played around here, but as
far as I know I should name all classes there as well.

I have no idea why this is not working. Can somebody help me out here.
Thanks
Re: Inheritance problem with Id in subclass [message #487818 is a reply to message #485541] Thu, 24 September 2009 13:58 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This should work fine. My guess is it is not finding Person, or its @Entity. Are you listing your classes in your persistence.xml, do you list Person. Also ensure you don't have an old version of the Person class on your classpath.

Try turning logging on to finest to get an idea of what is occurring.


James : Wiki : Book : Blog : Twitter
Previous Topic:MOXy - mapping enums
Next Topic:criteria API: select count(*) from ..
Goto Forum:
  


Current Time: Thu Apr 25 23:20:39 GMT 2024

Powered by FUDForum. Page generated in 0.02764 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top