-->
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: OneToOne mapping between superclass and subclass
PostPosted: Sat Feb 19, 2011 7:16 am 
Newbie

Joined: Thu May 13, 2010 3:44 am
Posts: 2
Hi,
I'm having a trouble in my application when trying to map superclass and subclass by OneToOne relationship. For example:
I have 2 classes: A and B, B extends A.
Code:
public class A {
      private int id;
      private String name;
}

public class B extends A {
      private int age;
}


I want to map OneToOne between those 2 classes by their IDs, but I don't know how to put annotations on class B. Both of them have table in database and in each table, there's a ID column. Could you please help me to resolve this issue? Thank you very much.


Top
 Profile  
 
 Post subject: Re: OneToOne mapping between superclass and subclass
PostPosted: Sun Feb 20, 2011 8:14 am 
Newbie

Joined: Sun Feb 20, 2011 7:08 am
Posts: 7
Hi Napoleon,
I think the reason you've not had any responses so far is that it's not very clear what you are trying to do.
The problem has been abstracted so much that it doesn't really make sense:

You're saying all entities of type A must be associated to a B.
You're also saying that all Bs are As.
Thus all Bs must also be associated to a B, giving you a recursive nightmare.

Can you make this into more of a real world example?, explaining what you are actually trying to do, rather than giving an attempted solution.

Also, have a look into things such as @MappedSuperClass, @AssociationOverride and @Embeddable as these may help you to solve your problem.

Let us know if you sort it out.
Thanks,
Owen


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.