Hi all,
I'm trying to map a very exotic relationship. Please don't bother to change the db model in order to make it work. This is what I got to work with, end of discussion. *sorry*
I cannot either post the hbm.xml or any code. But ask me for info, I'll try to post what I can. I'm very sorry!
We got tables: A, B, BC, C, BCD, D
The relationship is:
Code:
A --* B --* BC *-- C
|
*
BCD *-- D
A one-to-many B
B one-to-many BC
BC many-to-one C
BC one-to-many BCD
BCD many-to-one D
I've mapped all of these as classes. Each of the classes have its own hbm.xml file. And the relationships (everywhere) is mapped as bi-directional. Unsaved-value strategy is "null".
The problem is that I get a "cannot insert value NULL into column..." on table BCD. The object graph I'm trying to save is:
Code:
A1 --- B1 --- BC1 --- C1
| |
+- B2 --- BC2 -+
Contiuned (problems drawing ASCII database relationships) from above:
Code:
BC1 --- BCD1 --- D1
|
BC2 --- BCD2 -+
Each relationship object (BC and BCD) contains en extra field in addition to the foreign keys.
The SQL generated for BCD is wrong (due to my mapping, unsaved-value strategy or something else).
It should be:
Code:
insert into BCD (extraField, foreignKeyBC, foreignKeyD, primaryKeyBCD)
But the generated SQL is:
Code:
insert into BCD (extraField, foreignKeyD, primaryKeyBCD)
I can see from the debug messages that the BC is assigned a primary key and inserted before BCD is issued (that's fine).
I'm using UUIDGenerator as primary key for all classes.
Could anyone tell me how to proceed with my problem?
Kindest regards, Andreas