select Query Run for hibernateTemplate.save()
I am using hibernate 3.5.0 final with spring.In this I want to save data to a table which has a composite key associated from three other tables.I have used hibernateTemplate.save().But when I see the logs it clearly shows that there is a select happening before every insert.I am not able to identify the reason still.
Please help!
Mapping:
<hibernate-mapping>
<class name="class1" table="EVENT_ASSET_DISPOSITION">
<composite-id name="id" class="Idclass">
<key-property name="pk1" type="java.math.BigInteger">
<column name="PK_1" precision="38" scale="0" not-null="true"/>
</key-property>
<key-property name="pk2" type="long">
<column name="PK_2" not-null="true" />
</key-property>
<key-property name="pk3" type="long">
<column name="PK_3" precision="38" scale="0" not-null="true"/>
</key-property>
</composite-id>
<property name="column1" type="java.math.BigDecimal" generated="insert">
<column name="COLUMN_1" precision="38" scale="0" />
</property>
</开发者_运维技巧hibernate-mapping>
SQL:-
[STDOUT] (pool-14-thread-1) insert into TABLE_1 (COLUMN_1,PK_1,PK_2,PK_3) values (?, ?, ?, ?,) 2011-02-14 08:28:30,312 INFO [STDOUT] (pool-14-thread-1) Hibernate: select table1_.COLUMN_1 as COLUMN1_280_ from TABLE_1 as table1_ where table1_.PK_1=? and table1_.PK_2=? and table1_.PK_3=?
Cheers, Dwarak
One mechanism that hibernate uses to decide if an object is transient or not is versioning
if you add a version column to your mapping/object it should solve the problem
<version name="version" column="version" type="integer" unsaved-value="undefined"/>
EDIT 1:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-version
@see section 5.1.9
The log shows that select
is issued after insert
. It's caused by the fact that column1
is declared as generated="insert"
, therefore Hibernate need to fetch generated values of that column after insert
.
See also:
- 5.5. Generated properties
精彩评论