posted 15 years ago
hi,
In one of my tables, the composite key is consist of one auto increment key and one foreign key; this composite key is used as foreign key in some tables.
In the hibernate mapping, <composite-id> doesn’t allow <generator>, so i enabled the auto increment property for ID filed at data base level.
Because of this scenario, the records are getting inserted in parent as well as child table but the ID which is auto increment key is not getting inserted in child table where as it has been generated by database for respective record.
E.g.
In tb1 table, the composite key is consist of ,
ID - an auto increment key (at database level)
fk_ID - a foreign key
This composite key is used as a foreign key in tb2 and other table as well.
So when trying to insert the record, the ID has been generated and records are getting inserted in both the tables tb1 and tb2. but the value for ID in tb2 is null.
Can anybody tell me the solution?
one of the solutions for this problem, is using CompositeUserType for composite id class and then defining a custom IdentifierGenerator that populates the generated value into the composite key class.
But is there any other way?
Thanks,
Nishita