[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| 
Re: [eclipselink-users] remove childs in one-to-many
 | 
Hello Markus,
EclipseLink orders deletes last, allowing updates to occur first so that 
users can clean up any unmapped constraints with updates.  This behavior 
can be changed by calling setShouldPerformDeletesFirst(true) on 
UnitOfWork, which is accessible through the EntityManager:
 UnitOfWork uow = (UnitOfWork)( (JpaEntityManager)em.getDelegate() 
).getActiveSession( em ); uow.setShouldPerformDeletesFirst(true);
If the foreign key field has a non-nullable constraint, it should not be 
set to null in the object model.   Garbage collection should not be 
hindered by keeping the emp->Department reference; as long as nothing is 
referencing employee, it should be available for garbage collections. 
Similar question and answer are posted here:
http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg04021.html
Best Regards,
Chris
Hahn, Markus wrote:
Hi folks,
we encounter a problem with EL. We migrate from Kodo where different 
things worked which do not in EL.
-       In a one-to-many relation i want to remove a child from the 
collection in the parent:
-       Department dept = em.find(Department.class, 30);
-       Employee emp = dept.getEmployees.getFirst();
-       dept.getEmployees().remove(emp);
-       emp.setDepartment(null);
After some further steps in the transaction there is a flush, and EL 
tries to update emp, to set the department foreign key to null, which 
causes a foreign key constraint violation.
This looks like an error because this behaviour does not occur at all 
relations with the same mapping.
We think that the code is correct in the sense that the OR-Mapper has 
to respect the need to remove the relation on the Java object in order 
to be enabled to be garbage collected.
Mapping from the parent side is configured with private-owned and 
cascade-all.
Mapping back from the child to the parent is configured with 
cascade-merge, cascade-persist
We use EL 1.2
Any ideas or hints would be appreciated.
Regards, Markus
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users