|
Re: Delete from collection [message #537533 is a reply to message #537417] |
Wed, 02 June 2010 19:09 |
Gilberto Caetano de Andrade Messages: 45 Registered: July 2009 |
Member |
|
|
Hi,
from persistence-2_0-final-spec:
Quote: | Bidirectional relationships between managed entities will be persisted based on references held by the
owning side of the relationship. It is the developer's responsibility to keep the in-memory references
held on the owning side and those held on the inverse side consistent with each other when they change.
In the case of unidirectional one-to-one and one-to-many relationships, it is the developer's responsibil-
ity to insure that the semantics of the relationships are adhered to.
|
This one is may test:
@Test
public void romeveBidirectional() throws Exception {
log.debug("\nGetting an Vehicle by ID.\n");
Vehicle v = em.find(Vehicle.class, "LC100");
log.debug("Object loaded: \n" + v);
assertEquals(v.getColor(), "RED");
assertEquals("Should have 2 stays", v.getStays().size(), 2);
for (Stay s : v.getStays()) {
if (s.getId().equals(100)) {
v.getStays().remove(s);
s.setVehicle(null);
}
}
//Another way:
//Stay s = em.find(Stay.class, 100);
//v.getStays().remove(s);
//s.setVehicle(null);
tx.begin();
em.merge(v);
tx.commit();
assertEquals("Should have 1 stays", v.getStays().size(), 1);
}
Gilberto
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03855 seconds