-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException in org.hibernate.util.MarkerObject
PostPosted: Wed May 24, 2006 9:24 am 
Newbie

Joined: Wed May 24, 2006 9:03 am
Posts: 3
Hi there,

I'm getting a mysterious ClassCastException when I run my java code as JUnitTestCase. I'm getting following exception, when I try to call criteria.uniqueResult() in some situations - but there seems to be no regularity for this appearance. Difficult.... I know... :(

Exception Stack:
Code:
java.lang.ClassCastException: org.hibernate.util.MarkerObject
   at org.hibernate.engine.StatefulPersistenceContext.getCachedDatabaseSnapshot(StatefulPersistenceContext.java:277)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.getDatabaseSnapshot(DefaultFlushEntityEventListener.java:511)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:472)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:190)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:954)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1526)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
   at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
   at easy.util.SessionInfo.findByCriteriaUniqueResult(SessionInfo.java:290)
....



Class easy.util.SessionInfo:

Code:
...
286    public static <T extends PersistentObject> T findByCriteriaUniqueResult(Class<T> clazz, Criterion criterion) {
287        Criteria criteria = currentHibernateSession(clazz).createCriteria(clazz);
288        if (criterion != null)
289            criteria.add(criterion);
290        return (T) criteria.uniqueResult();
291    }
...


Hibernate version:
Hibernate 3.1.3
Hibernate Annotations 3.1.0 beta10

I've tried Google and ForumSearch as usual but with no result this time.
Thanks in advance for any help! If more information is needed, please let me know...

GreenTurtle


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:13 am 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
This looks like something that you need to look at in a debugger. If you have the Hibernate source, you can set a break point in org.hibernate.engine.StatefulPersistenceContext.getCachedDatabaseSnapshot(). It is apparently expecting something other than a org.hibernate.util.MarkerObject which it is getting somewhere in that method. If you don't have the source, it is freely available. I have found it useful to step thru the Hibernate classes on occasion.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:33 am 
Newbie

Joined: Wed May 24, 2006 9:03 am
Posts: 3
Ok, I will try to solve this issue by debugging the hibernate-code but the problem is, that it appears only occasionally. That's why debugging will be very time intensive, I fear... but it's the only way to solve it if there is no other idea.

Thanks for your answer!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 11:50 am 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
Which version of Hibernate are you using? For 3.1, this is the source code:

public Object[] getCachedDatabaseSnapshot(EntityKey key) {
//TODO: assertion failure if NO_ROW
return (Object[]) entitySnapshotsByKey.get(key);
}

The exception occurs on the "return" line. The little TODO comment isn't reassuring.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 5:20 am 
Newbie

Joined: Wed May 24, 2006 9:03 am
Posts: 3
Thanks for your help!

With your tips I debugged and found that function entitySnapshotsByKey.get(key); in some cases returned NO_ROW and then an exception is thrown.

Searching the web for this problem I found the following page:
http://www.mail-archive.com/hibernate-d ... 05542.html

There is a "workaround" given to prevent this exception:

-- Bug in StatefulPersistenceContext, causing classcast exception --

replace:

Code:
public Object[] getCachedDatabaseSnapshot(EntityKey key) {
   //TODO: assertion failure if NO_ROW
   return (Object[]) entitySnapshotsByKey.get(key);
}


with:

Code:
public Object[] getCachedDatabaseSnapshot(EntityKey key) {
     Object result = entitySnapshotsByKey.get(key);
     if(result==NO_ROW){
         return null;
     } else {
         return (Object[]) result;
     }
}


This worked fine for me but I'm not sure, if the results of my SQL-statements are correct all the time, because I don't really understand the rest of the linked post above. :-/

Thanks again!
GreenTurtle


Top
 Profile  
 
 Post subject: Has this been reported?
PostPosted: Fri Sep 22, 2006 1:29 pm 
Newbie

Joined: Fri Sep 22, 2006 1:22 pm
Posts: 3
Does anyone know if this is a known defect? I have looked at the lasted code and the issue is still there, and I cannot find anything in jira.

I dont want to report an issue which is either known or not really an issue in Hibernate but in user code.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 3:13 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 1:08 pm
Posts: 42
I've filed an issue:

http://opensource.atlassian.com/project ... e/HHH-2112


Top
 Profile  
 
 Post subject: Non Hibernate Work around
PostPosted: Fri Oct 27, 2006 11:35 am 
Newbie

Joined: Fri Oct 27, 2006 11:33 am
Posts: 1
Location: Maine
Is there a workaround, for this issue that doesn't require a hibernate recompile, and deployment?

-MrHighSide


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