-->
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: strange List.clear() behaviour
PostPosted: Mon Dec 15, 2003 8:54 am 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
On a simple one-to-many mapping:

Code:
    <class name="entities.Instrument" table="DAT_INSTRUMENT">
        ...
        <bag name="prices" table="DAT_PRICE" cascade="all" inverse="true" lazy="true" >
            <key column="FK_INSTRUMENT"/>
            <one-to-many class="entities.Price"/>
        </bag>
    </class>



on a simple class:

Code:

    public class Instrument implements Serializable {

        ...
        private List prices = new LinkedList();
        ...

        public void setPrices(List prices) {
            this.prices = prices;
        }

        public List getPrices() {
            return prices;
        }

    }
       



when I try this code:


Code:
        Iterator it = session.iterate("from Instrument inst where inst.code = 'I-1107280'");

        while (it.hasNext()) {
            Instrument instrument = (Instrument) it.next();
            instrument.getPrices().clear();

            session.saveOrUpdate(instrument);
        }



I expect that all Prices entities attached to selected Instruments should be deleted without being initialized.

I bet I've done something wrong somewhere since the Prices list get initialized but nothing in it is deleted.

Any hint ? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try using cascade="all-delete-orphan". This should delete the prices without parent instruments.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:27 am 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
Correct but I thought Hibernate would issue a one-shot delete in this case.

Why isn't it happening ?


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.