选择Query Run for hibernateTemplate.save() [英] select Query Run for hibernateTemplate.save()

查看:115
本文介绍了选择Query Run for hibernateTemplate.save()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用hibernate 3.5.0 final与spring。在这个我想保存数据到一个表有一个复合关键字从三个其他tables.I已经使用hibernateTemplate.save()。但是当我看到日志它清楚地表明在每次插入之前有一个选择发生。我无法找出原因。



请帮助!



映射:

 < hibernate-mapping> 
< class name =class1table =EVENT_ASSET_DISPOSITION>
< composite-id name =idclass =Idclass>
< key-property name =pk1type =java.math.BigInteger>
< column name =PK_1precision =38scale =0not-null =true/>
< / key-property>
< key-property name =pk2type =long>
< column name =PK_2not-null =true/>
< / key-property>
< key-property name =pk3type =long>
< column name =PK_3precision =38scale =0not-null =true/>
< / key-property>
< / composite-id>
< property name =column1type =java.math.BigDecimalgenerated =insert>
< column name =COLUMN_1precision =38scale =0/>
< / property>
< / hibernate-mapping>

SQL:
$ b $ (?,?,?,?,)
插入到TABLE_1(COLUMN_1,PK_1,PK_2,PK_3)中的[STDOUT](pool-14-thread-1)b 2011-02-14 08: 28:30,312 INFO [STDOUT](pool-14-thread-1)休眠:从table_1中选择table1_.COLUMN_1作为COLUMN1_280_作为table1_,其中table1_.PK_1 =?和table1_.PK_2 =? and table1_.PK_3 =?



干杯,
Dwarak

解决方案

日志显示选择插入之后发出。这是由于 column1 被声明为 generated =insert的事实,因此Hibernate需要获取生成的值code>插入。



另请参阅:




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

解决方案

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:

这篇关于选择Query Run for hibernateTemplate.save()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆