I am getting an issue considering the variety of queries made by hibernate towards the database. Here's my query log (using Mysql 5.1) towards the database when you are performing an easy choose:

111125  7:18:30
27 Query    SET autocommit=0
27 Query    SELECT @@session.tx_isolation
27 Query    select this_.id as id34_0_, this_.media_id as media3_34_0_, this_.message as message34_0_, this_.user_id as user4_34_0_ from notifications this_
27 Query    rollback
27 Query    SET autocommit=1

I have read a great deal about setting autocommit to after which to at least one. I understand the default for any connection is 1 which behavior can't be transformed. You are able to run SET autocommit = but it makes sense exactly the same.

Can there be anyway to prevent any one of individuals queries? I'm not sure why the Choose @@session.texas_isolation is going on and also the rollback. After I make use of a transaction I recieve a commit after which a rollback. Unsure why a rollback is definitely cabled.

Thanks!

My conf: Spring 2.5.6, Hibernate 3.6., Mysql 5.1

datasoure.xml:

<bean id="dataSource" destroy-method="close"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />

    <property name="initialSize" value="3" />
    <property name="maxActive" value="20" />
    <property name="minIdle" value="3" />
    <property name="poolPreparedStatements" value="false" />
    <property name="defaultAutoCommit" value="false" />
    <property name="defaultTransactionIsolation" value="4" />
</bean>

Transaction manager definition:

<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

UPDATE: Handled to get the rollback by setting new property

<property name="defaultReadOnly" value="true" />

The main problem now is you can't create a modification (whether I set around the transactional annotation readOnly=false) towards the db giving a SQLException. This property sets the bond readonly to true. I am speculating there is no method of doing this with HibernateTemplate.

I personally use aspectj transaction for inner code weaving.

<aop:aspectj-autoproxy proxy-target-class="true" />

You have to configure transactions for the application. Begin to see the Spring 2.5.x documentation on transaction management.

Edit 12/3/11: For techniques that only do chooses, you've still got to produce a read only transaction to be able to take away the extra queries you pointed out inside your publish. Just write @Transactional(readOnly=true) and you ought to be all set.

Edit 12/20/11: Additionally you need make certain transactions are set up properly. It appears such as the configuration you published might be missing < texas:annotation-driven /> annotation. See section 10.5.1 of the Spring documentation.