-->
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.  [ 5 posts ] 
Author Message
 Post subject: load() problem: Unknown entity
PostPosted: Fri Apr 27, 2007 2:16 am 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
Hi,

I get my Company from the Hibernate Session though a get() call successfully. I store this in my HttpSession and upon the next request I call load(myCompany, myCompany.getId()) to reassociate it with the new Hibernate session. I get the exception as shown below though.

It seems as if the proxy gets retrieved and stored in the HttpSession and Hibernate doesn't know what to do with it upon the load. First off, this seems strange to me. A load() call with the proxy as an argument should just work right?

Secondly, I tried making sure my Company was completely loaded before storing it in my HttpSession by calling get(Company, myCompany.getId()). I still get the same exception.

When I set lazy="false" in my Company mapping file, it works fine. But obviously I don't want to always load all Companies to just solve this one problem. Do I misunderstand how Hibernate should work or am I doing something wrong?

Thank you for your help,
Joost Schouten



-----The exception ----------
org.hibernate.MappingException: Unknown entity: com.jsportal.buisinessadmin.beans.Company$$EnhancerByCGLIB$$dc673e43
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:64)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:784)
at com.jsportal.buisinessadmin.transactionManagement.HibernateResource.load(HibernateResource.java:185)
at com.jsportal.buisinessadmin.web.JSFaces.Logon.init(Logon.java:337)
... 45 more

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:44 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi joostschouten,

try session.load(Company.class, myCompany.getId())

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 7:06 am 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
That did do the trick. I was hoping however that there would be a way to pass the object to load so that all references to it are not lost.

For now it works but I'm still puzzled as to why the initial load as discussed above does not work. Any clues?

Thank you,
Joost

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 7:16 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
We have no end of problems caused by people putting Domain objects into the session as hibernate looses the reference to them and things like lazy-loading just break horidly.
My advice to you would be don't but anything in your HttpSession ever, if you need to just store the Id and any other bits of information that you might need and then get it back out again when you need to.
If you want to store the whole thing, make a simple VO and put that into the session.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 7:18 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi joostschouten,

That is best practice to use load.And you forgot to give credit

_________________
Dharmendra Pandey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.