Hi all,
I am having trouble using Hibernate as JPA provider. I must be also missing something, altough I've read the docs many times.
I want to create a
bidirectional parent-child association, where the
parent is the only responsible for managing the association.
Since I'm using DTO's, I have to make the ejb <> dto conversion.
I have a method updateScenario() that receives a full-blown scenario, including the dependency elements collection. This collection can contain new elements (which do not have id), and old ones (which do have an id).
Because I have to use dtos, when I update my scenario I'm merging an unmanaged scenario instance that was converted from my DTO:
Code:
public void updateScenario(ScenarioEJB scenario) {
em.merge(scenario);
}
but that doesn't work. Can you tell me what I am doing wrong?
Hibernate version: 3.2.5.GA, with Hibernate entity manager 3.3.1.GA
Mapping documents:This is the parent mapping
Code:
@Entity
@Table(name = "OMP_SCENARIO")
public class ScenarioEJB implements java.io.Serializable {
...
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "scenario")
@JoinColumn(name = "SCENARIO")
@Cascade(value = { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public Set<ScenarioDependencyElementEJB> getDependencyElements() {
return dependencyElements;
}
This is the child mapping
Code:
@Entity
@Table(name = "OMP_SCENARIO_DEP_ELEMENT")
public class ScenarioDependencyElementEJB implements java.io.Serializable {
...
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "SCENARIO", insertable = true, updatable = true, nullable = false)
public ScenarioEJB getScenario() {
return scenario;
}
Full stack trace of any exception that occurs:org.springframework.orm.hibernate3.HibernateSystemException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: ScenarioEJB.dependencyElements; nested exception is org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: ScenarioEJB.dependencyElements
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:659)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:95)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:306)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:62)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:212)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:146)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:631)
(...)
Name and version of the database you are using:Oracle 10G
Code: