IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes hibernate hbm for this relation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "hibernate hbm for this relation" Watch "hibernate hbm for this relation" New topic
Author

hibernate hbm for this relation

sachin y deshpande
Greenhorn

Joined: May 12, 2004
Posts: 20
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

Joined: Feb 05, 2001
Posts: 16622

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: hibernate hbm for this relation
 
MyEclipse, The Clear Choice