-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem saving object in long transaction
PostPosted: Fri Dec 05, 2003 1:02 am 
Newbie

Joined: Fri Dec 05, 2003 12:44 am
Posts: 16
Hello,

I'm currently in the process of migrating from CastorJDO to Hibernate (I have to say this is soooo overdue!) and have run into an exception I don't really understand.

Code:
net.sf.hibernate.HibernateException: reassociated object has dirty collection reference
        at net.sf.hibernate.impl.OnLockVisitor.processCollection(OnLockVisitor.java:68)
        at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
        at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
        at net.sf.hibernate.impl.AbstractVisitor.process(AbstractVisitor.java:93)
        at net.sf.hibernate.impl.SessionImpl.reassociate(SessionImpl.java:1611)
        at net.sf.hibernate.impl.SessionImpl.lock(SessionImpl.java:1631)
        at ourcommunity.util.hibernate.HibernateHelper.saveOrUpdateCopy(HibernateHelper.java:224)
        at ourcommunity.giving.dao.GivingDAO.updateAppeal(GivingDAO.java:92)
        at ourcommunity.giving.GivingManagerEJBImpl.updateAppeal(GivingManagerEJBImpl.java:128)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke0(Native Method)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke(Unknown Source)
        at COM.jrockit.reflect.VirtualNativeMethodInvoker.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
        at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
        at org.jboss.ejb.Container.invoke(Container.java:700)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke0(Native Method)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke(Unknown Source)
        at COM.jrockit.reflect.VirtualNativeMethodInvoker.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
        at org.jboss.invocation.http.server.HttpInvoker.invoke(HttpInvoker.java:163)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke0(Native Method)
$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
        at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
        at org.jboss.ejb.Container.invoke(Container.java:700)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke0(Native Method)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke(Unknown Source)
        at COM.jrockit.reflect.VirtualNativeMethodInvoker.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
        at org.jboss.invocation.http.server.HttpInvoker.invoke(HttpInvoker.java:163)
        at COM.jrockit.reflect.NativeMethodInvoker.invoke0(Native Method)


What's happened is that I've loaded an object sent it off to a remote GUI client application where it's been modified and then sent it back to be updated into the DB. I guess the problem is related to the client replacing the collection but I don't really understand why this is a problem.

The actual elements of the collection shouldn't have changed just the collection its self.


Thanks,

Oliver Hutchison

www.ourcommunity.com.au


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 1:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are not allowed to lock() a dirty detached object. You should use update() instead. In this case, it is a null collection reference that causes the problem. Hibernate thinks you dereferenced a collection. (Actually, arguably Hibernate shouldn't throw an exception in this case - it should probably just silently ignore it.)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 1:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually, no, its not a null collection reference that causes the problem, it is a reference to an array or unwrapped collection.

This is exactly how Hibernate should behave.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 1:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
The actual elements of the collection shouldn't have changed just the collection its self.


You should avoid this kind of thing in Hibernate. The collection wrapper tracks changes to the collection so that updates can be performed efficiently.

You *are* allowed to do it, but its inefficient.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 1:58 am 
Newbie

Joined: Fri Dec 05, 2003 12:44 am
Posts: 16
That's all very well if your application is all in one JVM but what happens when the objects have to be serialized etc...

I just wrote a simple test case where I loaded an object, serialized it to a byte array and then de-serialized it and attempted to saveOrUpdate it and I still received the same exception. This was all done in the same JVM and there was no modification to the object except for the serialization/de-serialization.

Quote:
You *are* allowed to do it, but its inefficient.


Ummm It doesn't seem like it to me? What am I doing wrong?

I understand why it's inefficient to replace the collections. Though in the case of my objects I don't think it would be that great a hit as the collections are all quite small.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 2:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't know what you're doing wrong. You are allowed to do this.

Quote:
That's all very well if your application is all in one JVM but what happens when the objects have to be serialized etc...


There is absolutely no problem with that.


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