-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Select before insert with composite-id
PostPosted: Thu Jun 14, 2007 6:29 am 
Newbie

Joined: Sat Mar 13, 2004 9:46 am
Posts: 10
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.