Hi,
i have the following Problem in my Spring/Hibernate application:
I have created some Unit-Tests to test my Database-Layer code.
I want to save a list of ojects into my Oracle-Database. All the save operations are excecuted in the same transaction. If one of these saves fails due to a database error (Unique-Constraint) the elements written before the error occured are not rolled back.
Here is my Configuration:
A Dao which does the work
And a service class that calls the daoCode:public void save(List<E> elements) throws HibernateException { for (E element : elements) { sessionFactory.getCurrentSession().saveOrUpdate(element); } }
I call the saveAll function from a Spring Unit Test environment with a list containing three elements.Code:@Transactional(readOnly = false) public void saveAll(List<E> list) { dao.save(list); }
The second element contains a key which does already exist in the database table so a error is thrown when the transaction ist commited.
Although the transaction seems to be rolled back the first entry is written to the database. If i move the false entry to the end of the list both the first and second entry are commited.
Here is my database configuration:
I am using Hibernate 3.6.4 and Spring 3.0.5Code:<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@xxx" /> <property name="username" value="xx" /> <property name="password" value="xx" /> </bean> <!-- Transaktionsmanagement --> <bean id="transactionManager" scope="singleton" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="datasource"></property> </bean> <!-- Transaktionsmanagement �ber Annotation. --> <tx:annotation-driven /> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="datasource" /> <property name="mappingResources"> <list> ... </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.cache.use_second_level_cache">false</prop> <prop key="hibernate.cache.use_query_cache">false</prop> <prop key="hibernate.connection.autocommit">false</prop> </props> </property> </bean>
Appatently the session data is written after the session.close in org.springframework.orm.hibernate3.SessionFactoryU tils.closeSessionOrRegisterDeferredClose(session, sessionFactory)
At the moment this only occurs in an testing environment and i can't test if it does in produciton because this does not exist.
Is this an error or am i missing something?


Reply With Quote
