• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate hbm for this relation

 
sachin y deshpande
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have few tables which look like this:
Table 2
t2col1 auto generated indentity
t2col2

Table 3
t3col1 auto generated indentity
t3col2

Table 4
t4col1 auto generated indentity
t4col2

Table 1
t1col1 foreign key referneces Table 3 (t3col1), Table 4 (t4col1)
t1col2 foreign key references Table 2 (t2col1)
t1col3 auto generated indentity
t1col4
and (composite) primary key = t1col1, t1col2, t1col3

Note: t1col1 can have a fk from t3col1 or t4col1
t1col2 value would be decided if value in t1col1 is from table 3 or table4
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, but understand that in Database and database terms "t1col1 foreign key" is invalid term. It is not a foreign key relationship in a database. You can say that the field can store either the PK id from tab3 or tab4, but there cannot be any referential integrity called a Foreign Key.

Your solutions are down to needing to add another field to say whether it is from tab3 or tab4, and also you will probably want to create a CompositeUserType, see Hibernate's documentation on how to implement that.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic