Hi Everyone:
I am using Spring 2.0 and Hibernate 3.1. I am seeing "Select" statements when inserting a row into the database using Hibernate. After the insert, I see an update to the database. Is this normal? If not what can I do to tune it so it just does an insert.
Any suggestions to tune Hibernate so that it does not do a "Select" and "Update" would be appreciated. The batch stuff gives me headaches, when it lose the Session and throws an exception when it can not perform the batch updates.
In my Spring DAO I am using the HibernateTemplate.
import org.springframework.orm.hibernate3.HibernateTemplate;
public void insertCollection(Collection collection){
this.hibernateTemplate.saveOrUpdateAll(collection);
}
Spring config stuff
<bean id="dbSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="myDataSource"/>
</property>
<property name="mappingResources">
<list>
<value>asset.hbm.xml</value>
<value>assetmungo.hbm.xml</value>
<value>assetgroup.hbm.xml</value>
<value>assetAttributeMap.hbm.xml</value>
<value>attribute.hbm.xml</value>
<value>parentAttributeMap.hbm.xml</value>
<value>parentMungo.hbm.xml</value>
<value>assetPublication.hbm.xml</value>
<value>parentAsset.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!--
Oracle (any version)
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
Oracle 9i/10g
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
-->
<prop key="hibernate.dialect">org.hibernate.dialect.SybaseAnywhereDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.c3p0.min.size">5</prop>
<prop key="hibernate.c3p0.max.size">20</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.idle_test_period">300</prop>
<prop key="hibernate.jdbc.batch_size">200</prop>
</props>
</property>
</bean>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.xxxx.xxxx.ingestion">
<class name="com.xxxx.xxxx.ingestion.mungo.AssetMungo" table="Citi_Mungo">
<id name="id" column="id" type="long"/>
<property name="csAssetGroupId" column="cs_assetgroupid" type="long"/>
<property name="csAttrId" column="cs_attrid" type="long"/>
<property name="floatvalue" column="floatvalue" type="float"/>
<property name="intvalue" column="intvalue" type="long"/>
<property name="stringvalue" column="stringvalue" type="string"/>
<many-to-one name="asset" column="cs_ownerid" class="CitiAsset"/>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.xxxx.xxxx.ingestion">
<class name="CitiAsset" table="Citi">
<id name="id" column="id" type="long"/>
<property name="flextemplateid" column="flextemplateid" type="long"/>
<property name="createdBy" column="createdby" type="string"/>
<property name="status" column="status" type="string"/>
<property name="name" column="name" type="string"/>
<property name="description" column="description" type="string"/>
<property name="updatedby" column="updatedby" type="string"/>
<property name="updatedDate" column="updateddate" type="timestamp"/>
<property name="createDate" column="createddate" type="timestamp"/>
<!-- Here we map the attributes to the Citi_Mungo-->
<set name="attributes"
table="Citi_Mungo"
cascade="save-update"
inverse="true">
<key column="cs_ownerid"/>
<one-to-many class="com.xxxx.xxxx.ingestion.mungo.AssetMungo"/>
</set>
<!-- Map to the Citi_AMap table and let Hibernate handle the transitive persistence -->
<set name="attributeMap"
table="Citi_AMap"
cascade="save-update"
inverse="true">
<key column="ownerid"/>
<one-to-many class="com.xxxx.xxxx.ingestion.AssetAttributeMap"/>
</set>
<set name="assetGroup" table="Citi_P_Group" cascade="save-update" inverse="true">
<key column="childid"/>
<one-to-many class="com.xxxx.xxxx.ingestion.AssetGroup"/>
</set>
<!-- Here we set the one-to-one relationship with the AssetPublication table -->
<one-to-one name="assetPub" class="com.xxxx.xxxx.ingestion.AssetPublication" cascade="save-update"/>
</class>
</hibernate-mapping>
Hibernate:
select
assetmungo_.id,
assetmungo_.cs_ownerid as cs2_1_,
assetmungo_.cs_assetgroupid as cs3_1_,
assetmungo_.cs_attrid as cs4_1_,
assetmungo_.floatvalue as floatvalue1_,
assetmungo_.intvalue as intvalue1_,
assetmungo_.stringvalue as stringva7_1_
from
Citi_Mungo assetmungo_
where
assetmungo_.id=?
Hibernate:
insert
into
Citi_Mungo
(cs_ownerid, cs_assetgroupid, cs_attrid, floatvalue, intvalue, stringvalue, id)
values
(?, ?, ?, ?, ?, ?, ?)
Hibernate:
update
Citi_Mungo
set
cs_ownerid=?,
cs_assetgroupid=?,
cs_attrid=?,
floatvalue=?,
intvalue=?,
stringvalue=?
where
id=?
|