-->
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.  [ 1 post ] 
Author Message
 Post subject: load() and get() return wrong subclass?
PostPosted: Tue Apr 19, 2005 11:43 am 
Newbie

Joined: Thu Mar 03, 2005 11:07 am
Posts: 6
Hibernate version: 2.1.7c

Hi there,

I have a class Animal and two subclasses Cat and Dog:

Animal
-->Cat
-->Dog

using joined subclasses. In the database, there is one instance of Cat with id 1 and one instance of Dog with id 2.
When I execute:

Cat cat = (Cat) session.load(Cat.class, 1);
Dog dog = (Dog) session.load(Dog.class, 2);

everything is fine. However, when I execute:

Cat cat = (Cat) session.load(Cat.class, 1);
Dog dog = (Dog) session.load(Dog.class, 2);
Dog dog = (Dog) session.load(Dog.class, 1);

I get a ClassCastException instead of a ObjectNotFoundException? Also: only the first two lines result in a database access. Hibernate seems to ignore the fact that I'm trying to load Dog with id 1 (which does not exist) and retrieves the previously loaded Cat with id 1 from the cache, thus resulting in a class cast exception? The same thing happens with get()! What am I missing?

Thanks,
Jonas


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

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.