« Return to Thread: How to xml-code a hibernate one-to-one?

Re: How to xml-code a hibernate one-to-one?

by TheStijn :: Rate this Message:

| View in Thread

thanks Dave,

I think I prefer the first solution < less XML editing.
But I'm a bit stuck on how to implement this exactly in conjunction with Spring.

This is the way I write my test classes:

@SpringApplicationContext( {
                "classpath:com/m4w/common/props/spring/common-data-test.xml",
                "classpath:com/m4w/common/props/spring/common-dao.xml" })
@DataSet
@RunWith(UnitilsJUnit4TestClassRunner.class)
@Transactional(TransactionMode.ROLLBACK)
public class UserDAOTest extends AbstractHibernateDAOTest {

    @SpringBeanByType
    private UserDAO userDao;

    @Test
    public void getAll() throws Exception {
        final List<User> result = this.userDao.getAll();
        assertEquals(3, result.size());
    }
}

So, how can I implement either solutions without completely refactoring the way my unit tests are created?

thanks,
Stijn

Dave S-B wrote:
In HSQLDB you can do the following in your setup();

dbUnitConnection.getConnection().prepareStatement("set
referential_integrity FALSE").execute();

...where dbUnitConnection is the DBUnit IConnection. Then do the load
using a database operation (e.g. DatabaseOperation.REFRESH). Then do this...

dbUnitConnection.getConnection().prepareStatement("set
referential_integrity TRUE").execute();

The second idea just involves making a normal DBUnit XML dataset file
(see http://www.dbunit.org/components.html#FlatXmlDataSet) and then
copying the XML for the user data to the end and modifying it by hand
(or search & replace). If you use a REFRESH operation then DBUnit will
insert data if it's not already there (based on the primary key of the
database table) or update the row if the primary key already exists.

Dave S-B

 « Return to Thread: How to xml-code a hibernate one-to-one?