-->
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.  [ 1 post ] 
Author Message
 Post subject: update many-to-many
PostPosted: Wed Feb 18, 2009 1:14 pm 
Newbie

Joined: Sat Jan 10, 2009 8:19 am
Posts: 4
Hi

I have two classes: Lista and Adresaci.
When I insert values from jTable Hibernate fills join table with 2 FK (one from Lista, second from Adresaci).

This works fine:

Session session=factory.openSession();
Transaction tx=session.beginTransaction();
Lista list = new Lista();
list.setNazwa(jTextField7.getText());
list.setUwagi(jTextField5.getText());
session.save(list);
int j = jTable1.getRowCount();
for (int i=0;i<j;i++){
String klucz= jTable1.getValueAt(i,0).toString();
int kluczyk = Integer.parseInt(klucz);
Adresaci adresat = (Adresaci) session.get(Adresaci.class,kluczyk);
list.getAdresaci().add(adresat);
adresat.getListy().add(list);
}
tx.commit();
session.close();

but how I should update if for example I inserted two rows:

join table Listy

id_adr id_lista
186 187
185 187
188 187

and I have in jTable1 just 2 rows like:
join table Listy

id_adr id_lista
181 187
188 187

So Hibernate should delete rows: id_adr 186,185 and insert id_adr 181

lista.hbm.xml
<set name="adresaci" table="listy" lazy="true" inverse="true">
<key column="id_lista"/>
<many-to-many column="id_adr" class="Adresaci"/>
</set>

adresaci.hbm.xml

<set name="listy" table="listy">
<key column="id_adr"/>
<many-to-many column="id_lista" class="Lista"/>
</set>

thanks
mk


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.