Frankly speaking, I am running out ideas on how to get it work and I need your help please!!!!
is there a way to describe an association between any two tables where there are no foreign constraints at all in a hibernate mapping file.
Let me give you an example:
We have three tables: table1, table2, table3.
Table 1 and 2 have only a primary key column
Table3 has three columns: pk, relatedTableName, relatedObjPk
Table1 has following items:
PK
1
2
Table2 has following items:
PK
1
2
3
Table3 contains records from Table1 and Table2:
PK RelatedTableName RelatedObjID
1 Table1 1
2 Table1 2
3 Table2 1
3 Table2 2
We have three concrete classes Entity1, Entity2, and Entity3 for each of the Tables.
class Entity1
{
Long pk;
Collection<Entity3> entity3; // how to map this collection
}
class Entity2
{
Long pk;
Collection<Entity3> entity3; // how to map this collection
}
class Entity3
{
Long pk;
String relatedEntityName;
Long relatedEntityPk;
Object relatedObj; // this can be mapped using <any>
}
We want to know how to map the collections in Entity1 and 2 in hibernate mapping file so that we can use HQL to traverse the relationships.
Jianping
|