Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate 1-0,1 relationship

 
Samuel Cox
Ranch Hand
Posts: 96
Scala Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My team and I have been struggling with situations where a member object of a class might be null.

For instance:


Class B might never get populated. Our DB designer says A is the parent of B so B should have a foreign key reference to A. We can't seem to map this using one-to-one. We have tried many-to-one from A to B with unique="true" doesn't work if we have As without Bs (NULL violates uniqueness constraint). The only thing that I can see is the one-to-one using a primary key association, which would make the primary key in B match that of A. However, my DB guy really wants the foreign key relationship to be visible.

Any help is appreciated.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for parent-child relationships between tables hibernate typically has a <subclass> XML mapping element. That again drills down to two conditions.
Whether the parent child relationships are in a single table(something like manager-employee, Cat-kittens) or two different tables (Car - benz, human - Samuel Cox).
you can map both of these relationships using hibernate.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can refer to this article.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic