I am using Hibernate through JBoss Seam 2.0.1 in an EJB3 environment (JPA).
I have an
EndUser entity whose profile contains one or more email addresses. The relationship is annotated as follows:
Code:
@Entity
public class EndUser implements Serializable
{
...
@OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy="user")
@IndexColumn(name="id")
public List<Email> getEmails()
{
...
}
...
}
@Entity
public class Email implements Serializable
{
...
@ManyToOne
@JoinColumn
public EndUser getUser()
{
...
}
...
}
If I delete the user, the associated email also gets deleted according to the cascade. During my testing, I deleted the user whose email was the first entry in the email table (id=1). After I deleted that user, all operations that load an
EndUser instance began to fail with:
Code:
org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:107)
org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:145)
org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:557)
org.hibernate.type.EntityType.resolve(EntityType.java:379)
org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
org.hibernate.loader.Loader.doQuery(Loader.java:729)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
When I look in the database, I cannot find any association between the user and email with id 1.
However, if I create a bogus row in the DB with email id 1, everything runs happily.
Any ideas what is going on here?
Thanks.
-Raj