• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate One to One association documentation inconsistency

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic