-->
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: ehcache and WrongClassException
PostPosted: Tue Jul 05, 2005 4:34 pm 
Newbie

Joined: Thu Mar 04, 2004 5:03 am
Posts: 18
Hibernate version: 2.1.8

I am having the following problem:

I have a class hierarchy mapped to one table like so:

AbstractClass discriminator-value="null"
|-> ConcreteClass1 discriminator-value="C1"
|-> ConcreteClass2 discriminator-value="C2"
|-> ConcreteClass3 discriminator-value="C3"

My discriminator column is defined as such:
Code:
<discriminator
            column="obj_type"
            not-null="true"
            type="string"
            length="2"/>


I try the following:

Code:
// load an object, it is actually an instace of ConcreteClass3
Object o = session.load(AbstractClass.class, 3);
// ....
// change a couple of properties
// ...
session.saveOrUpdate(o);


Then in a different session:
Code:
Object o = session.load(AbstractClass.class, 3);


This second time a WrongClassException is thrown along the lines:
Object with id: 3 was not of the specified subclass: ConcreteClass1 (loaded object was of wrong class)

Notice, how it thinks I have specified the loaded class as ConcreteClass1.

After a lot of trial and error I tried switching off ehcache; and surprisingly enough it works flawlessly. Also, if I have the cache enabled, and I let some time pass between saving and reloading it works fine presumably because the relevant cache entry has expired.

Has anyone else encountered this weird behavior? I haven't found the solution myself after a lot of searching and I would appreciate any tips.

Many thanks,
Giorgos


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 4:23 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
This seems like an age old topic, but I am experiencing the same problem with ehcache and hibernate 3.2.2.ga.

I have a table per hierachy mapping:
Code:
          AbstractClass
           ^         ^
           ||       ||
ConcreteClass1   ConcreteClass2

Now, I have a collection mapped to AbstractClass. When hibernate tries to load this collection, while an instance of one of the concrete classes is already cached with ehcache, it throws a WrongClassException. This exception claims that the instance was not of the expected class AbstractClass but instead of the class ConcreteClass1.

Hey... an object of ConcreteClass1 is also an AbstractClass object!

Here is a stack trace:
Code:
   org.hibernate.WrongClassException: Object with id: 64 was not of the specified subclass: AbstractClass (loaded object was of wrong class class ConcreteClass1)
   at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java(Compiled Code))
   at org.hibernate.loader.Loader.getRow(Loader.java(Compiled Code))
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java(Compiled Code))
   at org.hibernate.loader.Loader.doQuery(Loader.java(Compiled Code))
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java(Compiled Code))
   at org.hibernate.loader.Loader.loadCollectionSubselect(Loader.java:2057)
   at org.hibernate.loader.collection.SubselectOneToManyLoader.initialize(SubselectOneToManyLoader.java:58)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java(Compiled Code))


Has this ever been fixed in some newer version of hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 5:32 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
bump


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 6:24 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
bump


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 4:49 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
bump


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.