hibernate question ?

T

tomo

Let's say i have table A, and table B that are in a m:n relationship with
table C thas hold's their id's.
And then I save one record in table A that is linked to two records in table
B, through table C.Now I
don't want that link anymore, i wan't to delete 2 rows in table C that are
holding this info. Is this
possible without deleting records from table a and table b ?



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4640 (20091126) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
J

Jean-Baptiste Nizet

Let's say i have table A, and table B that are in a m:n relationship with
table C thas hold's their id's.
And then I save one record in table A that is linked to two records in table
B, through table C.Now I
don't want that link anymore, i wan't to delete 2 rows in table C that are
holding this info. Is this
possible without deleting records from table a and table b ?

Of course :

@Entity
public class A {
// ...
private Set<B> bs = new HashSet<B>();

public void removeBs() {
bs.clear();
}
}

Be careful that, if your relationship is bidirectional, both sides of
the relationship should be maintained and stay coherent, which can be
tricky and can lead to infinite loops if badly done.

@Entity
public class A {
// ...
private Set<B> bs = new HashSet<B>();

public void removeBs() {
for (B b : bs) {
b.removeA(this);
}
bs.clear();
}
}
 
L

Lew

tomo said:
Let's say i have table A, and table B that are in a m:n relationship with
table C thas hold's their id's.
And then I save one record in table A that is linked to two records in table
B, through table C.Now I
don't want that link anymore, i wan't to delete 2 rows in table C that are
holding this info. Is this
possible without deleting records from table a and table b ?

It's certainly possible in the database itself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top