Please correct my understanding: I can not cause a NonUniqueObjectException when I just loaded the object. I am *not* changing the id, just some properties.
Some other relevant info is that I am updating a class "Project" and receiving the exception about "Issue". This is Hibernate 2.1.1. Just reproduced it under 2.1.2 as well.
I am receiving the following:
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: c5bb43a8fa0d03a200fa127ba9940002, of class: com.terravox.issuetracker.model.Issue
at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1605)
at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1377)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1403)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1327)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2557)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2197)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2186)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:339)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:297)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:110)
at com.terravox.issuetracker.view.EditEntityForm.onSubmit(EditEntityForm.java:69)
Here is the relevant code:
public ModelAndView onSubmit(Object command) throws ServletException {
final String[] ignoreProperties = {"id"};
final BeanWrapper wrapper = new BeanWrapperImpl(command);
final Object finalCommand = command;
// Do the update in a tx
transactionTemplate.execute( <<<<==== ***Line 69***
new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
if (log.isDebugEnabled()) {
log.debug("Transaction Status: " + status.isNewTransaction());
}
Object existing = dataManager.retrieve(
(String) wrapper.getPropertyValue("id"));
BeanUtils.copyProperties(finalCommand, existing, ignoreProperties);
dataManager.update(existing);
// No return needed
return null;
}
});
return new ModelAndView(getSuccessView());
}
"dataManager.retrieve()" is a straight wrap around Session.load().
Any thoughts?
Thanks,
A.
--
Adam Sherman
Tritus CG Inc.
+1 (613) 797-6819
http://www.tritus.ca/