Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Foreign Key Relationships problem in Hibernate  RSS feed

 
Deepak Ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a very unique problem in Hibernate. I will try to explain the problem as clearly as possible.

I have a table A which has three columns 1, 2 and 3. These 3 columns are nullable columns.

I have a table B which has fields 4 and 5 as its compund key. Now, the table A has a foreign key relationship with table B through fields 1 and 4 and also 2 and 5.

I have another table C which has fields 6 and 7 as its compond key. The table A has a foreign key relationship with table C through fields 3 and 6 and also 2 and 7.

Now, my problem is since the field 2 in table A is related to both Table B amd table C, Hibernate is not allowing me to use insert=true and update=true for the relationships of table A and B and table A and C. If i do so, then at startup, hibernate throws me an error to set either one of the relationships as false. If i set either one of the relationships as false, then i am not able to update the database with the required value since I am explicitly setting the insert and update as false.

I need to update fields 1, 2 and 3, but the relationships is not allowing me to do so. Please let me know what can be done for the above issue.

I tried using native SQL to update the tables. But I got an exception saying that only HQL should be used for insert/update.

Please let me know if there is any other way.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak,
Welcome to JavaRanch!

Our Hibernate experts hang out in the Object Relational Mapping forum. I'll move your post over there for you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!