The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
Author

Hibernate One to One association documentation inconsistency

Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Messages: 233

I've done One to Many associations with no problem, but for some reason my One to One association isn't working correctly.

I originally set it up according to the Chapter 5 Hibernate documentation.



However, it doesn't seem to be working. The Chapter 7 Hibernate documentation gives a different setup to use. It wants me to include a column field and a unique field. Neither of which are listed in the Chapter 5 info. I tried adding a column field, but Eclipse gave me an error.



Anybody know why the documentation is inconsistent? Or am I just missing something?

Thanks.
Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Messages: 233

Okay, it looks like I need to put one-to-one tags in both classes. But then it complains that I don't have a getter in one of my classes. I don't need bidirectional functionality for this relationship.

The only other thing I've seen is to do it with a many-to-one and the unique constraint, but that seems hokey.



Also, if I'm setting it up using the two one-to-one tags, do I need to have a setter in both objects, or can I do it with just one? Will Hibernate automatically populate the fields? I'm thinking it doesn't, but want to make sure.
Justin Chi
Greenhorn

Joined: Sep 09, 2009
Messages: 13

Bai Shen wrote:Okay, it looks like I need to put one-to-one tags in both classes. But then it complains that I don't have a getter in one of my classes. I don't need bidirectional functionality for this relationship.

The only other thing I've seen is to do it with a many-to-one and the unique constraint, but that seems hokey.



Also, if I'm setting it up using the two one-to-one tags, do I need to have a setter in both objects, or can I do it with just one? Will Hibernate automatically populate the fields? I'm thinking it doesn't, but want to make sure.


I am afraid it is not document inconsistent , your original set-up (like Chapter 5) is primary key association , while the new one (like Chapter 7) is unique foreign key association.


This message was edited 1 time. Last update was at by Justin Chi Jian Jun

 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
replay challenge