Hi.
I am having a problem with integration testing w/ Hibernate and Spring. During multiple calls (see code snippits below) in a test case Hibernate will complain with this error:
Code:org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [com.tabarca.domain.User#71]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.tabarca.domain.User#71] org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.tabarca.domain.User#71] at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:586) at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72) at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:579) at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:750) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358) at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:744) at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:740) at com.tabarca.dao.hibernate.GenericHibernateDAO.delete(GenericHibernateDAO.java:31) at com.tabarca.domain.logic.TabarcaImpl.deleteUser(TabarcaImpl.java:47) at ... [snipped for readability]
I have tried to force hibernate to flush and evict after add/update/delete calls with no success. Any ideas?
Here is the snip from the test case
It dies on the line: this.bizImpl.deleteUser(user);
Here is the relevant Hibernate code snipCode:public abstract class AbstractUserIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests { protected BizFacade bizImpl; public void setBizImpl(BizFacade bizImpl) { this.bizImpl= bizImpl; } public void testDeleteUser() { // Add user to database User user = new User(); user.setFirstname("Blake"); user.setLastname("Tucker"); user.setUsername("btucker"); user.setPassword("tuckb989"); user.setEmail("forget@about.it"); this.bizImpl.addUser(user); // Assert that user is saved to database List<User> users = this.bizImpl.findAllUsers(); Assert.assertEquals("Incorrect number of users found", users.size(), 1); // Delete user this.bizImpl.deleteUser(user); // Assert that user has been deleted from database users = this.bizImpl.findAllUsers(); Assert.assertEquals("Incorrect number of users found", users.size(), 0); } }
Any help would be greatly appreciated.Code:public class GenericHibernateDAO<T, ID extends Serializable> extends HibernateDaoSupport implements GenericEntityDAO<T, ID> { private Class<T> persistentClass; public GenericHibernateDAO(Class<T> persistentClass) { this.persistentClass = persistentClass; } public T add(T entity) throws DataAccessException { this.getHibernateTemplate().merge(entity); return entity; } }
Thanks,
Ibexx


Reply With Quote