-->
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.  [ 3 posts ] 
Author Message
 Post subject: clear() not working with DELETE_ORPHAN cascade annotation
PostPosted: Thu Oct 13, 2005 7:41 pm 
Newbie

Joined: Sun Jul 10, 2005 9:52 pm
Posts: 1
Hullo,

I'm having a problem with modifying child collections that are declared with the DELETE_ORPHAN cascade type. When I do a clear() on the collection, it complains with an UnsupportedOperationException (see below for stack trace). I noticed that the HbmBinder calls Collection.setOrphanDelete when the delete-orphan element is specified, but AnnotationBinder does no such thing (that I can see). That hasOrphanDelete property plays an important role in determining whether a clear() is queued or not. I tried setting this property to true through the debugger and found that everything worked correctly as a result.

So, is the fact that AnnotationBinder doesn't call setOrphanDelete a bug (if so I'll log a JIRA), or is there a good reason why it doesn't (and perhaps I'm doing something wrong?).

Thanks,

Ben

Hibernate version: 3.1 rc 1 with annotations 3.1beta6

Mapping documents:

Code:
@Entity
@Proxy(lazy=false)
public class Price extends BusinessObject {

    @OneToMany(mappedBy="price", cascade=CascadeType.ALL)
    @OrderBy(clause="priceRuleId")
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    public Set<PriceRule> getRules() {
        return rules;
    }
    ...
}


Code between sessionFactory.openSession() and session.close():

price.getRules().clear();
session.flush();

Note: price is connected to the session

Full stack trace of any exception that occurs:

Caused by: java.lang.UnsupportedOperationException: queued clear cannot be used with orphan delete
at org.hibernate.collection.PersistentSet$Clear.getOrphan(PersistentSet.java:375)
at org.hibernate.collection.AbstractPersistentCollection.getQueuedOrphans(AbstractPersistentCollection.java:515)
at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:341)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:318)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:713)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:711)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 5:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Fixed in CVS, thanks.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: RE: clear() not working with DELETE_ORPHAN cascade annotatio
PostPosted: Mon Nov 14, 2005 10:32 pm 
Newbie

Joined: Tue Apr 19, 2005 7:36 pm
Posts: 9
Location: San Francisco, CA
I was having an issue with deleting the child element using clear() as well, but my problem was that I was not using the DELETE_ORPHAN cascade annotation. Once I added it, using clear() to remove the list elements works for me (using 3.1rc2 with annotations 3.1beta6 (downloaded today).

This is what my parent mapping looks like:

Code:
@Entity(access = AccessType.PROPERTY)
@Proxy(lazy = false)
class Parent {
    ...

    @OneToMany(cascade = CascadeType.ALL,
                fetch = FetchType.EAGER,
                targetEntity = ChildImpl.class)
    @JoinColumn(name ="parent__id",
                nullable = false,
                updatable = false,
                insertable = true
    )
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Set<Child> getChildren() {
        return children;
    }
}


It would be nice to mention about @Cascade extension in the Hibernate Annotations documentation. Basic search on either @Cascade or DELETE_ORPHAN yields no results.


Thank you,
Zeel.

_________________
Thanks,
Zeel.

Software Developer, Audiologist/DJ, Cookie Monster
All Original Electronic Music - download MP3s:
=> http://www.polygroovers.com/


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