ellen wrote:
Hibernate version: 3.2.2
Name and version of the database you are using: MySQL 5.0.38
There are table A with PK column idA and table B with PK column idB. The cardinality between table A and B is ManyToMany so that I created table C with PK(idA, idB) as linking table for table A and B. There are also two additional columns in table C. All these three tables are correctly mapped as three entities, with bidirectional references between Table A/Table C and Table B/Table C. In another word, Class A has a collection of Class C and Class B has a collection of Class C too. Now there is a web form for submitting new instance of Class A. The same web form also submits the infomation which should be stored in the linking table.
idA, the PK of table A, is generated automatically by the underlying database. I am not sure how to persist this web form in an optimal way. Say, when the user filled the form, idA is still unknown, I have to persist it to get its id (do I?), all idBs would be fetched via a DB query. Then, the links with additional information will be stored into table C. My question is, how do I get the database generated idA in this unit of work? Thanks for any enlightenment!
After saving the object of the pojo class using session, use the method getIdentifier using session and pass the object of pojo in this. This method is used to generate DB generated Id. I had used like this.