-->
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.  [ 2 posts ] 
Author Message
 Post subject: Different beans, same table: ClassCastException
PostPosted: Sun Nov 14, 2004 7:21 am 
Newbie

Joined: Tue Apr 20, 2004 3:51 am
Posts: 2
Hibernate version: 2.1

I've two beans, FullCompany and ShortCompany. The last one is used only to retrieve a small set of "Company" properties, just to show a list and to avoid big data tranfer (FullCompany is a very big bean). I cannot change, by now, this situation refactoring the beans (or even the db).

Both beans are mapped on the same table. If, IN THE SAME SESSION, I retrieve a ShortCompany bean (eg. with id 27) and then I retrieve a FullCompany bean (with id 27) Hibernate return always the same ShortCompany bean (id 27), so I get a ClassCastException, casting the load(...) return value to FullCompany.

fullCompany = (FullCompany)session.load(FullCompany.class, id);

gives back the id 27 ShortCompany bean

Obviously, if I close the session and open another one, all works correctly.

Is this behaviour ok?

Stefano.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 11:55 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
yes this is expected.
You cannot have two representations of the same row in the same session.

this can help
http://www.hibernate.org/41.html

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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