Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reverse engineering a one to one relationship

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay,

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.
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup - I definetly had the reverse constraint for uniquenss in there.... Im using the hibernate reverse engineering tool in the jboss ide.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic