Here are the methods from a facade class, with irrelevant stuff removed.
Code:
public void deleteAssignment(long mapId, long relId, long assignmentId)
throws SystemException, FinderException {
this.assignmentDAO.deleteAssignment(mapId, relId, assignmentId);
}
public Assignment mergeAssignments(long mapId, long relId, List assignmentIds, String label,
UserContainer user)
throws SystemException, FinderException {
/* Create new assignments that contains all concepts from the given assignments. */
Assignment newAsgn = this.assignmentDAO.mergeAssignments(
mapId, relId, assignmentIds, label, user);
/* Delete all assignments whose concepts were merged. */
for (Iterator it = assignmentIds.iterator(); it.hasNext(); ) {
long assignmentId = ((Long)it.next()).longValue();
this.deleteAssignment(mapId, relId, assignmentId);
}
return newAsgn;
}
Here are the DAO object methods (that talk to Hibernate):
Code:
public void deleteAssignment(long mapId, long relId, long assignmentId)
throws SystemException, FinderException {
try {
/* Get the assignment from the DB. Make sure we don't get a stale
* instance of Assignment from the Hibernate cache.
*/
Assignment assignment = this.getAssignment(mapId, relId, assignmentId);
this.hibernateTemplate.evict(assignment);
assignment = this.getAssignment(mapId, relId, assignmentId);
/* Delete the assignment from the DB. */
this.hibernateTemplate.delete(assignment);
this.hibernateTemplate.flush();
} catch (DataRetrievalFailureException e) {
throw new FinderException(e.getMessage(), e);
} catch (Exception e) {
throw new SystemException(e.getMessage(), e);
}
}
public Assignment mergeAssignments(long mapId, long relId, List assignmentIds, String label,
UserContainer user)
throws SystemException, FinderException {
try {
Assignment newAsgn = this.createAssignment(mapId, relId, label);
for (Iterator it = assignmentIds.iterator(); it.hasNext(); ) {
long assignmentId = ((Long)it.next()).longValue();
Assignment asgn = this.getAssignment(mapId, relId, assignmentId);
newAsgn.merge(asgn, user);
}
this.hibernateTemplate.save(newAsgn);
this.hibernateTemplate.flush();
return newAsgn;
} catch (DataRetrievalFailureException e) {
throw new FinderException(e.getMessage(), e);
} catch (Exception e) {
throw new SystemException(e.getMessage(), e);
}
}
The DAO class is an member variable of the facade class.
I am calling mergeAssignments(). It works fine if I comment out the calls to this.deleteAssignments() (in the loop). If the calls is there, it fails.
Here is the exception trace, if it can help:
Code:
org.hibernate.engine.PersistenceContext.checkUniqueness(Ljava.io.Serializable;Lorg.hibernate.persister.entity.EntityPersister;Ljava.lang.Object;)V(PersistenceContext.java:586) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(Lorg.hibernate.event.SaveOrUpdateEvent;Ljava.lang.Object;Lorg.hibernate.persister.entity.EntityPersister;)V(DefaultSaveOrUpdateEventListener.java:254) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(Lorg.hibernate.event.SaveOrUpdateEvent;)V(DefaultSaveOrUpdateEventListener.java:214) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(Lorg.hibernate.event.SaveOrUpdateEvent;)Ljava.io.Serializable;(DefaultSaveOrUpdateEventListener.java:91) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(Lorg.hibernate.event.SaveOrUpdateEvent;)Ljava.io.Serializable;(DefaultSaveOrUpdateEventListener.java:69) at org.hibernate.impl.SessionImpl.saveOrUpdate(Ljava.lang.String;Ljava.lang.Object;)V(SessionImpl.java:468) at org.hibernate.engine.Cascades$5.cascade(Lorg.hibernate.engine.SessionImplementor;Ljava.lang.Object;Ljava.lang.String;Ljava.lang.Object;Z)V(Cascades.java:154) at org.hibernate.engine.Cascades.cascadeAssociation(Lorg.hibernate.engine.SessionImplementor;Ljava.lang.Object;Lorg.hibernate.type.Type;Lorg.hibernate.engine.Cascades$CascadingAction;Lorg.hibernate.engine.Cascades$CascadeStyle;ILjava.lang.Object;Z)V(Cascades.java:771) at org.hibernate.engine.Cascades.cascade(Lorg.hibernate.engine.SessionImplementor;Ljava.lang.Object;Lorg.hibernate.type.Type;Lorg.hibernate.engine.Cascades$CascadingAction;Lorg.hibernate.engine.Cascades$CascadeStyle;ILjava.lang.Object;Z)V(Cascades.java:720) at org.hibernate.engine.Cascades.cascadeCollection(Lorg.hibernate.engine.Cascades$CascadingAction;Lorg.hibernate.engine.Cascades$CascadeStyle;Lorg.hibernate.type.CollectionType;Lorg.hibernate.type.Type;Ljava.lang.Object;ILorg.hibernate.engine.SessionImplementor;Ljava.lang.Object;Z)V(Cascades.java:895) at org.hibernate.engine.Cascades.cascadeAssociation(Lorg.hibernate.engine.SessionImplementor;Ljava.lang.Object;Lorg.hibernate.type.Type;Lorg.hibernate.engine.Cascades$CascadingAction;Lorg.hibernate.engine.Cascades$CascadeStyle;ILjava.lang.Object;Z)V(Cascades.java:792) at org.hibernate.engine.Cascades.cascade(Lorg.hibernate.engine.SessionImplementor;Ljava.lang.Object;Lorg.hibernate.type.Type;Lorg.hibernate.engine.Cascades$CascadingAction;Lorg.hibernate.engine.Cascades$CascadeStyle;ILjava.lang.Object;Z)V(Cascades.java:720) at org.hibernate.engine.Cascades.cascade
It seems that it's trying to do a save or update just before the delete. But I can't figure out what it's updating.
Thanks.