-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: EntityNotFound exception for entity with id 1
PostPosted: Fri Nov 21, 2008 2:59 pm 
Newbie

Joined: Sat Jun 04, 2005 1:25 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 3:24 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think the problem may be related to.

Code:
@IndexColumn(name="id")


Is the 'id' column also the primary key column in the Email table? If so, this will give you problems, since the list should have no "holes". The index values should fill the list starting 0, 1, ... and so on up to the length of the list. The index column should be a separate column, otherwise you should use a Set instead of a List.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 5:56 pm 
Newbie

Joined: Sat Jun 04, 2005 1:25 pm
Posts: 2
Hi,
Thanks for your prompt response. It looks like this was a case bad exception message. The EntityNotFoundException does not say which entity was referencing the entity that was not found. After digging through the database, I found another table where the email was being referenced, but had not been deleted as part of the removal of EndUser.

I wish Hibernate had more descriptive error messages.

-Raj


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.