|
#1
|
|||
|
|||
|
Hi,
I have a very weird problem. I have a method doSomething() in a java application implemented in Spring. When I run the method without putting any decalarative transactions in the application-context.xml it works fine. But the moment I put the transactions like <prop key="doSomething">PROPAGATION_REQUIRED</prop> I start getting the error that says "Don't dereference a collection with cascade="all-delete-orphan": A.myCollection". If I change the cascade attribute to "all" instead of "all-delete-orphan" it starts working and I donot get any error. But I need to know that if the function works fine with "all-delete-orphan" cascade without using transactions, then why does it fail when I add transactions to it. Hibernate version:3.0 I have a class A wherein I have a collection of instances of class B in the following manner- Class-> class A{ private List myCollection; public void writeMyCollection(List myCollection) { this.myCollection = myCollection; } } Mapping documents-> <class name="A" table="A"> <id name="id" type="long" column="ID" unsaved-value="0"> <generator class="native"/> </id> <list lazy="true" name="myCollection" access="field" cascade="all-delete-orphan"> <key column="SOME_ID"/> <index column="SORT_INDEX"/> <one-to-many class="B"/> </list> </class> Code between sessionFactory.openSession() and session.close():-> public void doSomething(long id, List collection){ A a = (A) this.getHibernateTemplate().get(A.class, new Long(Id)); a.writeMyCollection(collection); } Full stack trace of any exception that occurs:-> org.springframework.orm.hibernate3.HibernateSystem Exception: Don't dereference a collection with cascade="all-delete-orphan": A.myCollection; nested exception is org.hibernate.HibernateException: Don't dereference a collection with cascade="all-delete-orphan": A.myCollection org.hibernate.HibernateException: Don't dereference a collection with cascade="all-delete-orphan": A.myCollection at org.hibernate.engine.Collections.processDereferenc edCollection(Collections.java:70) at org.hibernate.engine.Collections.processUnreachabl eCollection(Collections.java:38) at org.hibernate.event.def.AbstractFlushingEventListe ner.flushCollections(AbstractFlushingEventListener .java:211) at org.hibernate.event.def.AbstractFlushingEventListe ner.flushEverythingToExecutions(AbstractFlushingEv entListener.java:71) at org.hibernate.event.def.DefaultAutoFlushEventListe ner.onAutoFlush(DefaultAutoFlushEventListener.java :39) at org.hibernate.impl.SessionImpl.autoFlushIfRequired (SessionImpl.java:711) at org.hibernate.impl.SessionImpl.prepareQueries(Sess ionImpl.java:895) at org.hibernate.impl.SessionImpl.getQueries(SessionI mpl.java:885) at org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:834) Please let me know if you need any more details or anything is not clear. Thanks in Advance, Ashish Abrol |
|
#2
|
||||
|
||||
|
What version of hibernate are you using? In 3.1.3 I see the exception line being removed.
__________________
Costin Leau SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source" http://twitter.com/costinl Please use [ c o d e ] [ / c o d e ] tags |
|
#3
|
|||
|
|||
|
Thanks so much. After downloading Hibernate's 3.1.3 version I am no longer facing this issue and the problem seems fixed.
Regards, Ashish Abrol |
|
#4
|
|||
|
|||
|
Hello,
in my opinion it's not a problem with the hibernate version itselfs. You try to change the reference to the collection inside an object of type A. But this collection is mapped using "delete-all-orphan". A better solution would be to do something like that: public void writeMyCollection(List myCollection) { ... this.myCollection.clear(); this.myCollection.addAll(myCollection); ... } Take also a look at the following link: http://www.hibernate.org/117.html#A3 Hope i could help you Best regards, M. Puhlmann |
|
#5
|
|||
|
|||
|
This thread is rather old but maybe the following could help.
I had the same problem without ever touching the reference to the collection. It appears that the problem came from a bad transaction configuration. I use BeanNameAutoProxyCreator to wrap some beans in a TransactionInterceptor. One of those beans should not be wrapped, but its original name matches the patterns I specified. The business process uses that bean, giving unexpected transactional behaviour causing the problem. Just renaming the bean made my day. JCG |
![]() |
| Thread Tools | |
| Display Modes | |
|
|