• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate self reference

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make a self-reference, tried different solution, but it doesn't work.

what is the correct syntax ?

thanks.


the error is

 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert on this subject but I think that 2 things could have happened.

1. The tabel already existed and your db does not allow hibernate to override it.
2. The mappedBy does not have a correct value. I believe it should reference to a parent Product. Like this:
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we need this "private Product parent;", only for self-reference ?

thanks.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you have a bi-directional relation. If you want a uni-directional relation remove the parent and the mappedBy declaration.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic