Hello,
I ve tried to fix this issue on my project for hours but i still don't know why I m getting it.
Basicly I have two entities :
- Recommendation
- Criterion
mapped as follow :
Code:
public class Recommendation implements PkIntegerAware {
@Id
@Column(name="ID")
@GeneratedValue
private int id;
@Column(name="DESCRIPTION")
private String description;
@Column(name="IS_IMPROVEMENT")
private boolean improvement;
@ManyToOne
@JoinColumn(name = "CRITERION_ID",
referencedColumnName = "ID", updatable = false)
private Criterion criterion;
@Enumerated(EnumType.STRING)
@Column(name="RECOMMENDATION_STATUS")
private RecommendationStatus recommendationStatus;
.... getters & setters
}
Code:
@Entity
@Table(name = "criterion")
@NamedQueries({ @NamedQuery(name="criterion.findCriterionsByModelId",query="FROM Criterion c WHERE c.id=?")
})
public class Criterion implements PkIntegerAware {
@Id
@GeneratedValue
private int id;
@Basic
private String name;
@Basic
private int refWeighting;
@Basic
private int modelValue;
@Column(name="criterion_order")
private int order;
@ManyToOne
@JoinColumn(name = "MODEL_ID",
referencedColumnName = "ID", insertable = true, updatable = false)
private Model model;
@OneToMany(mappedBy = "criterion", fetch = FetchType.LAZY,
cascade = CascadeType.ALL)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Set<Recommendation> recommendations;
.... Getter/setters
Creating & updatings my recommendation entities does'nt make any problem, but trying to delete a Recommendation entity that way :
Code:
@Override
public void deleteRecommendation(Recommendation rParam) {
if(rParam == null) {
LOG.error("Can not delete a null Recommendation.");
} else {
GenericIntegerPkDAOImpl <Recommendation> recommendationDao = new GenericIntegerPkDAOImpl < Recommendation > (Recommendation.class);
EntityManager em = entityManagerFactory.createEntityManager();
recommendationDao.setEntityManager(em);
recommendationDao.delete(rParam);
}
}
the dao delete code :
Code:
/**
* delete the object from the database.
* @param object object to be deleted.
*/
public void delete(T object) {
getEntityManager().remove( getEntityManager().merge(object));
}
And the hibernate exception i get :
Quote:
...
Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [datamodel.Recommendation#<null>]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:598)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
... 55 more
The exception is raised on delete an entity which has an ID>0 and which is in database !
Any help would be much appreciated !
Thanks by advance
Patrice