Hello all
I came cross the lazy load problem when using junit to test my program.
I searched the forum and found the solution(Here is the link to that post:
(http://forum.springframework.org/showthread.php?t=9630). But as soon as I overcame that problem follow by the solution in that post, unfortunely I face another problem. my save operation seem not to be committed.
BTW:I use dbunit to test my database related code.
The following is the code snippet from my program:
1.The UnitTest code snippet
if I uncomment the commentted code, every thing goes well except the find method!And if I comment the code the test will come across the Lazy Load problem.Code:protected void setUp() throws Exception { super.setUp(); emptyAllTables(); entity = new Entity(); entity.setName("Test"); /* sessionFactory = (SessionFactory) BeanLocator.getBean("mySessionFactory"); Session session = SessionFactoryUtils.getSession(sessionFactory, true); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); */ } protected void tearDown() throws Exception { /* SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory); SessionFactoryUtils.closeSessionIfNecessary(sessionHolder.getSession(), sessionFactory); */ super.tearDown(); }
public void testFind()Code:public void testSave() throws SQLException, DataSetException { ITable table = connection.createQueryTable("ExceptedData", QUERY); assertEquals(0, table.getRowCount()); baseDAO.save(entity); table = connection.createQueryTable("ExceptedData", QUERY); assertEquals(1, table.getRowCount()); }
{
//.....
}
2.the save method
i am sure that the transaction haven't been committed, because i can't see any insertion info from the log file!Code:public Object save(Object object) { return getHibernateTemplate().save(object); }
where is the problem? how can I resolve this problem! Can anyone give me a hand?
thanx in advance for any suggestion!
Regards
Yoshiyan


Reply With Quote
