IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Hibernate One to One association documentation inconsistency Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate One to One association documentation inconsistency" Watch "Hibernate One to One association documentation inconsistency" New topic
Author

Hibernate One to One association documentation inconsistency

Bai Shen
Ranch Hand

Joined: Sep 24, 2008
Posts: 323
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
Posts: 323
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
Posts: 25
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.


 
 
subject: Hibernate One to One association documentation inconsistency
 
Threads others viewed
what is hibernate.hbm2ddl.auto property, what is its purpose exactly?
doubt in one-to-one association mapping
procedure calling using hibernate and springs and diff b/w hibernate and ejb 3.
is it possible to persist an ArrayList of POJO into database in hibernate?
Why exception coming on accessing collection
MyEclipse, The Clear Choice