Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Data Access

Reply
 
Thread Tools Display Modes
  #1  
Old Jun 12th, 2006, 04:17 AM
ashish.abrol ashish.abrol is offline
Junior Member
 
Join Date: Jun 2006
Posts: 5
Lightbulb Don't dereference a collection with cascade="all-delete-orphan"

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
Reply With Quote
  #2  
Old Jun 12th, 2006, 05:48 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,015
Default

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
Reply With Quote
  #3  
Old Jul 18th, 2006, 09:21 AM
ashish.abrol ashish.abrol is offline
Junior Member
 
Join Date: Jun 2006
Posts: 5
Default

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
Reply With Quote
  #4  
Old Aug 1st, 2007, 10:38 AM
mpuhlmann mpuhlmann is offline
Junior Member
 
Join Date: Aug 2007
Posts: 1
Default

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
Reply With Quote
  #5  
Old Jan 20th, 2009, 10:27 AM
jcgagne jcgagne is offline
Junior Member
 
Join Date: Jan 2009
Location: Switzerland
Posts: 1
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:54 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.