AbstractTransactionalJUnit4SpringContextTests MySQL data not getting rolled back?

Posted on Friday, June 18, 2010

0


We know that the unit tests should not be dependent on each other and hell there are not. But as soon as we switch our unit tests to use MySQL instead of HSQLDB which we use by default then it seems that hell breaks loose. The tests somehow become dependent on each other and start failing.

Wait, isn’t AbstractTransactionalJUnit4SpringContextTests supposed to help with the rollback?

All right after struggling with this for over 30 minutes and blaming it on the mysql driver, we finally realized that there are 2 dialects that you can have for MySQL since the database supports 2 kinds of db schemas. MyISAM the non transaction one and InnoDB the transactional one.

So we changed our dialect to use the transactional one and … the world was green!

This is how our properties file looks like now

#Properties file used for setting up application parameters
#to be run in an Development environment
hibernate.show_sql=true

#HSQLDB
#hibernate.hbm2ddl=create-drop
#hibernate.dialect=org.hibernate.dialect.HSQLDialect
#database.driverclass=org.hsqldb.jdbcDriver
#database.url=jdbc:hsqldb:mem:monitoringsystem
#database.username=sa
#database.password=

#MYSQL
hibernate.hbm2ddl=create
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
#hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
database.driverclass=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/monitoringsystem
database.username=root
database.password=root

Advertisements
Posted in: Database, hsqldb, Java, testing, Tip