Spring Hibernate MySQL Test doesn't roll back -
i have problem transactional tests using spring 3.0.5, hibernate 3 , mysql 5. in logs seems there's ok , transaction rolls back, got record inserted database. configuration this:
<bean id="hibernatedatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver" /> <property name="url" value="jdbc:mysql://localhost:3306/blog" /> <property name="username" value="user" /> <property name="password" value="password" /> <property name="defaultautocommit" value="false" /> </bean> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory" ref="hibernatesessionfactory" /> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="hibernatesessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean"> <property name="datasource" ref="hibernatedatasource" /> <property name="schemaupdate" value="true" /> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.mysql5innodbdialect</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.autocommit">false</prop> </props> </property> <property name="annotatedclasses"> <list> <value>pl.jedenpies.blog.domain.uzytkownik</value> </list> </property> </bean> <bean id="uzytkownikdao" class="pl.jedenpies.blog.db.hibernate.dao.hibernateuzytkownikdao"> <property name="sessionfactory" ref="hibernatesessionfactory" /> </bean>
test class:
@runwith(springjunit4classrunner.class) @contextconfiguration(locations = {"classpath:beans.xml"}) @transactionconfiguration(defaultrollback = true) public class uzytkownikdaotest { private uzytkownikdao uzytkownikdao; @test @beforetransaction public void test1config() { assert.notnull(uzytkownikdao, "uzytkownikdao nie moze byc null"); } @test @transactional @rollback public void test2create() { uzytkownik u = new uzytkownik(); u.setemail("my4@uzytkownik.pl"); u.sethaslo("blablabla"); assert.istrue(!u.isidustawione()); u = uzytkownikdao.create(u); assert.notnull(u, "uzytkownik nie moze byc null"); assert.istrue(u.isidustawione()); } @resource public void setuzytkownikdao(uzytkownikdao uzytkownikdao) { this.uzytkownikdao = uzytkownikdao; } }
log:
debug org.hibernate.event.def.abstractsaveeventlistener - executing identity-insert debug org.hibernate.jdbc.abstractbatcher - open preparedstatement (open preparedstatements: 0, globally: 0) debug org.hibernate.jdbc.abstractbatcher - insert uzytkownicy (email, haslo) values (?, ?) hibernate: insert uzytkownicy (email, haslo) values (?, ?) debug org.hibernate.id.identifiergeneratorfactory - natively generated identity: 43 debug org.hibernate.jdbc.abstractbatcher - close preparedstatement (open preparedstatements: 1, globally: 1) debug org.springframework.test.context.transaction.transactionaltestexecutionlistener - method-level @rollback(true) overrides default rollback [true] test context [[testcontext@3dbbd23f testclass = uzytkownikdaotest, locations = array<string>['classpath:beans.xml'], testinstance = pl.jedenpies.blog.dao.uzytkownikdaotest@22a010ba, testmethod = test2create@uzytkownikdaotest, testexception = [null]]] debug org.springframework.transaction.support.abstractplatformtransactionmanager - initiating transaction rollback debug org.springframework.orm.hibernate3.hibernatetransactionmanager - rolling hibernate transaction on session [org.hibernate.impl.sessionimpl@303bc1a1] debug org.hibernate.transaction.jdbctransaction - rollback debug org.hibernate.transaction.jdbctransaction - rolled jdbc connection debug org.hibernate.jdbc.connectionmanager - transaction completed on session on_close connection release mode; sure close session release jdbc resources! debug org.springframework.orm.hibernate3.hibernatetransactionmanager - closing hibernate session [org.hibernate.impl.sessionimpl@303bc1a1] after transaction debug org.springframework.orm.hibernate3.sessionfactoryutils - closing hibernate session
yes, googled lot problem didn't find solution. have no idea what's wrong.
any suggestions?
do using innodb engine? myisam default engine form mysql 5.x prior 5.5 , not support transactions - wikipedia - myisam
Comments
Post a Comment