-->
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.  [ 8 posts ] 
Author Message
 Post subject: Removing at one-to-many associasion
PostPosted: Mon Jan 26, 2009 3:25 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
Hello

I am having the following declaration in Limited.hbm.xml

Code:
<subclass name="Limited"
          extends="CorporateBO"
          discriminator-value="LTD">
          ....
        <bag name="directors" cascade="all" lazy="false">
            <key column="CORPORATE_ID" not-null="true"/>
            <one-to-many class="Director"/>
        </bag>
    </subclass>


and i am using the class Limited as follows

Code:
public class Limited extends CorporateBO{
    ....
    List directors = new ArrayList();

    public Limited(){

    }

    ...
public List getDirectors() {
        return directors;
    }

    public void setDirectors(List directors) {
        this.directors = directors;
    }
}


then i am using a Jframe to set the values at Limited and a Jframe to get the values for directors like this
Code:
if(bussiness instanceof Limited) {
             .....
             Vector data = directorModel.getDataVector();
             ((Limited)bussiness).setDirectors(data);       
              }


Everything works fine when i am doing insert or update but when i am removing a row from jtable then directors do not removed from table DIRECTORS as i have cascade="all".

Am i doing something wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 4:47 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Try to use cascade="all,delete-orphan" or cascade="all-delete-orphan".

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 5:27 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
I have tried but with same results .

I am getting the following results from hibernate if i enable show sql from hibernate


Code:
Hibernate:
.....
    /* create one-to-many row eurotheo.sheetaudit.bo.Limited.directors */ update
        DIRECTOR
    set
        CORPORATE_ID=?
    where
        DIRECTOR_ID=?
Hibernate:
    /* create one-to-many row eurotheo.sheetaudit.bo.Limited.directors */ update
        DIRECTOR
    set
        CORPORATE_ID=?
    where
        DIRECTOR_ID=?
.....
[quote]

Thera are only the update statemnts and not the delete statement if i remove a row from the vector directors[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 5:36 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You change the whole collection after you loaded your Limited-object:
Quote:
((Limited)bussiness).setDirectors(data);


When using delete-orphan, you should not change the collection object. Instead you could do the following, to update your limited's directors:
Code:
((Limited)bussiness).getDirectors().clear();
((Limited)bussiness).getDirectors().addAll(data);

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 6:48 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
i tryied but with some results

I if delete a Limited object then directors deleted from table as i expect.
I also tried to remove the full Directors collection
Quote:
((Limited)bussiness).getDirectors().clear();


but it does not work !!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 6:57 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Are you working on detached objects? Have you tried merge then? Did you change your mapping to use delete-orphan?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 7:22 am 
Newbie

Joined: Thu Jan 22, 2009 2:49 am
Posts: 13
Did you change your mapping to use delete-orphan?
yes


Have you tried merge then?
??
How can i do it?
Basically am using DAO like this
Limited limited = limitedDAO.getLimited(1);
...
limitedDAO.saveOrUpdate(limited);

Are you working on detached objects?
I think so!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 8:23 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Can you post your DAO implementation?

_________________
-----------------
Need advanced help? http://www.viada.eu


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