Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Order of operations in EclipseLink

As mentioned in the article listed below. EclipseLink (and many other Object-Relational providers) orders the deletes last because it facilitates maintenance of referential integrity. An O-R tool must do more than just send SQL to a database. It has to maintain the identity and the integrity of the relationships among the objects it is managing. (e.g. Imagine you delete an object that is part of a relationship. EclipseLink must be able to update any foreign keys that form the relationship before doing the delete, or you will get exceptions related to Foreign Key constraints)

You can control when different parts of you transaction are executed using the em.flush() API.

If you need to get at the performDeletesFirst API, you can use org.eclipse.persistence.jpa.JpaHelper.getEntityManager(entityManager) and call getUnitOfWork() on the returned JpaEntityManager.


Rohit Banga wrote:
  Hi Patric
See the following link <>

The above link shows how to configure it using UnitOfWork. Is there a way to do it using the EntityManager?


On 12/30/2010 4:56 PM, Michael Simons wrote:
Hi Patric,

AFAIK it is an intentional behaviour, EL just like any other JPA/JDO implementation that we've used (EL, OpenJPA, etc) do inserts before deletes.
I don't remember the reason. I just remember there was one. Maybe someone else can explain that to us.
To keep the AK you can either flush right after the delete or replace the delete/insert by an update.


-----Urspr√ľngliche Nachricht-----
Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] Im Auftrag von patric@xxxxxxxxxxx
Gesendet: Mittwoch, 29. Dezember 2010 14:27
An: EclipseLink-users@xxxxxxxxxxx
Betreff: [eclipselink-users] Order of operations in EclipseLink


imagine a simple table/entity TestTable with an AK on column status.

The following operations will fail using EclipseLink:

TestTable tt = new TestTable();


TestTable tt2 = new TestTable();
em.flush(); //this will throw an exception due to AK violation

However, I would expect a successfull run because I previously removed the record which has the same AK.

It seems that the operation order is modified by EclipseLink -
inserts seems to be executed first which might change the outcome of a set of operations.
Is this an intentional behaviour?
If it is, is there a possibility to preserve the operation order?

Thank you and best regards,

eclipselink-users mailing list
eclipselink-users mailing list

Thanks and Regards
Rohit Banga
Member Technical Staff
Oracle Server Technologies


eclipselink-users mailing list

Back to the top