File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate 1-0,1 relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate 1-0,1 relationship" Watch "Hibernate 1-0,1 relationship" New topic

Hibernate 1-0,1 relationship

Samuel Cox
Ranch Hand

Joined: Nov 16, 2004
Posts: 96


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

Joined: May 16, 2005
Posts: 661

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.

If you are not laughing at yourself, then you just didn't get the joke.
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 661

you can refer to this article.
I agree. Here's the link:
subject: Hibernate 1-0,1 relationship
It's not a secret anymore!