Hello,
I have two tables:
Table1:
id (Primary Key)
banr (Long)
panrentId
name
comment
....
Table2:
id (Primary Key)
banr (Long)
action
area
comment
The tables have a one to many relation. One dataset from table1 has many dataset of table2. The special at table1 is, that I save also the changes of the table in it. For example, I change anything in table1, i built a new dataset with the new entries and the old dataset gets the parentid from the new dataset.
Now I get a problem with the relation. Normaly I need a foreign Key in the table2 with table1_id. But then I have the problem with the foreign key of table2.
My solution is that I use the banr as foreign key, because the foreign key is in the new version always the same:
Table1:
id|banr|parentId|name|comment
1|12 |2 |test | no comment
2|12 |null |test | comment
Table2:
id|banr|action|area|comment
1|12 |open |3 |no comment
Now i want to get all datasets from Table1 where parentid=null and the Table2.area=3.
But the relation between the tables must be with the table1.banr = table2.banr.
In the database I could´t build the relation because the banr number in table1 is not uniqe. Unique is the banr+parentid, but the parentid can be null.
How I have to build the mapping to get a relation between the table1.banr an table2.banr?
Thank you for help,
Daniel
Hibernate version:3.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html