• Post Reply Bookmark Topic Watch Topic
  • New Topic

table with an fk that allows none existing id using hibernate  RSS feed

 
Renz Alexander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so basically i have this table that requires me to input the id of another table, wherein the values of for those id's does not exist yet. i'm not quite sure how to implement this with hibernate but i have a few thoughts on how it should work.

the first is i forgo the fk and just force the application to join the two via a join or by find id.

the second would be that i create a reference table containing the fk of the first and second table, with the second table being null-able, and another column which would contain a duplicate values of the second table's id as well as allow for the supposedly non existing values to exist.

the problem with the solutions are that of the added complexity of catching if both exist in both tables input form, the aforementioned forcing of the join as well as the loss of some of hibernates features. now I'm not gonna be picky with the solution i just wan't to know if their is a more elegant solution to the problems stated above. thanks to those who would reply
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is this a requirement? It defeats the purpose of having a foreign key constraint, if I understand what you're saying correctly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!