aspose file tools*
The moose likes Object Relational Mapping and the fly likes Transactional problems in accessing data using spring mock, dbunit and HSQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Transactional problems in accessing data using spring mock, dbunit and HSQL" Watch "Transactional problems in accessing data using spring mock, dbunit and HSQL" New topic
Author

Transactional problems in accessing data using spring mock, dbunit and HSQL

nagaraj kris
Greenhorn

Joined: Jan 12, 2007
Posts: 5
Hi,

I have setup a environment to write junits for my application(technology used :spring + hibernate + mysql + linux) using DBUnit and springmock.

I am finding trouble in accessing the data that was loaded by the DBUnit from a bean that was created by BeanFactory(SingletonBeanFactory).

Following is my setup:

I have a SampleTestCase class that extends AbstractTransactionalDataSourceSpringContextTests.

This class loads all the spring config files and data files which is used by DBUnit for data insertion. I am using HSQL in memory database, therefore all the tables are created on the fly using hibernate HBM2DDL option.

When i run this class with a method to test a create API, the following steps occur
- First all the tables are created using HBM
- Spring mock starts a new transaction
- Then DBUnit inserts all the data into tables
- Then the test method is executed
- Control goes to the ID generator class mentioned in the HBM file, id generator class creates another class CustomSequenceGenerator class using Beanfactory approach. This CustomSequenceGenerator queries the database for a sequence value that was loaded with DBUnit and scrambles it to return a primary key.

The problem is that the data loaded by dbunit is not visible for CustomSequenceGenerator class. But the same data can be accessed from the test class if i create CustomSequenceGenaratot object using applicationContext.

This particular use case uses both applicationContext and beanFactory approach of bean creation, which may be the reason for not being able to see the data loaded.

Can somebody help me in identifying the casuse and ways to overcome it.

Thanks,
Nag
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transactional problems in accessing data using spring mock, dbunit and HSQL