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 reverse engineering a one to one relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "reverse engineering a one to one relationship" Watch "reverse engineering a one to one relationship" New topic

reverse engineering a one to one relationship

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
hi guys : I have a database where

table a references table b, and the reference is unique, i.e.

Now, I've reverse engineered the dao code in hibernate but for some reason, I have the following in my API ...

Anyways. This is really bothering me, because it complicates the API unnecessarily.

Since a unique column referencing a table key that is also unique, this should always be a one to one relationship, right ?

How can you clue in hibernate to do a one to one instead of a set? (Yes I've defined ssid as unique in the database).
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265


What tool are you using to do the reverse engineering?

The table structure you have defined would actually be one-to-many; you haven't defined any reverse restriction that there's a unique constraint on person (name + ssid). This is assuming that by stating you've defined ssid as unique, you mean as the primary key of ref_ssid. If you mean in the person table, then that should be sufficient.

You may want to double check your FK was correctly defined. If you did it in the order you described, it would have failed, because you can't add a FK to a table/field that doesn't yet exist. i.e., try:

But not knowing the full details or what tool your using, these are just best guesses.

There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Yup - I definetly had the reverse constraint for uniquenss in there.... Im using the hibernate reverse engineering tool in the jboss ide.
I agree. Here's the link:
subject: reverse engineering a one to one relationship