-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @Id duplicate or missing when making inheritance
PostPosted: Thu Aug 20, 2009 8:03 am 
Newbie

Joined: Wed Feb 04, 2009 5:26 am
Posts: 5
Hi,

I can't find out how to make the following working :

@Table(name = "A")
@AccessType("field")
public abstract class A { ...}

@Entity
@Table(name = "B")
@AccessType("field")
public class B extends A {
@Id
@GeneratedValue
private long hId;

...
}

@Entity
@Table(name = "C")
@AccessType("field")
public class C extends B {
@Id
@GeneratedValue
private long hId;

...
}

The default behaviour seems to be ONE CLASS PER HIERARCHY. (Using default value for discriminant)

* if I put the @id (and long hId) in both B and C class, hibernate can't start telling that it's not possible to Override id.
* if I remove the id in the class C, Hibernate start normally, then I can store object instance of B but not instance of C. It says : "No column Id found".

The question is : how can I make hibernate works for a more than one level of concrete class inheritance ?
I'd like to instantiate and store (via hibernate) B & C instances. The problem seems to be where to place the Id ? how many of them is it legal to put ? where ?

Thx, JL.


Top
 Profile  
 
 Post subject: Re: @Id duplicate or missing when making inheritance
PostPosted: Thu Aug 20, 2009 10:00 am 
Beginner
Beginner

Joined: Fri Jun 26, 2009 6:59 am
Posts: 23
use:
@Inheritance(strategy = InheritanceType.JOINED)
on Class A and give class A the ID.
remove the ID's from classes B and C

hey presto, 3 tables linked by PFK.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.