Hibernate version:
3.2.3
Mapping documents:
Ticket.hbm.xml:
<class name="Ticket" table="sync_ticket">
<id name="id">
<generator class="identity"/>
</id>
<property name="code" column="code"/>
<set name="permissions" inverse="true" cascade="all">
<key column="id" not-null="true"/>
<one-to-many class="Permission"/>
</set>
</class>
Permission.hbm.xml:
<class name="Permission" table="sync_permission">
<composite-id class="Permission$Id" name="id">
<key-many-to-one name="ticket" class="Ticket" column="ticketId"/>
<key-property name="upId" column="permissionId"/>
</composite-id>
</class>
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
Hibernate: insert into sync_ticket (code) values (?)
Hibernate: select permission_.ticketId, permission_.permissionId from sync_permission permission_ where permission_.ticketId=? and permission_.permissionId=?
Hibernate: select permission_.ticketId, permission_.permissionId from sync_permission permission_ where permission_.ticketId=? and permission_.permissionId=?
Hibernate: insert into sync_permission (ticketId, permissionId) values (?, ?)
Hibernate: insert into sync_permission (ticketId, permissionId) values (?, ?)
I've two tables a Ticket table and a Permission table. The ticket table has a primary key id and permission table has a composite key (upId and ticketId). The primary key ticket.id is used as foreignkey in the permission table (references ticketId) and the upId is manually assigned. I'm encountering the strange behaviour that when I try to save an object graph (eg. one Ticket with two Permission objects) that there is a select statement executed before a permission is inserted. I assume that the select statement is executed to determine the ticketId key used as foreign key in permission. How to get rid of the extra select before insert?
Regards, dee.
|