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

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


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

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


@Entity @Table(name = "Customers")
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.
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: Sun May 20 19:34:45 GMT 2018

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

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

Back to the top