Community
Participate
Working Groups
Build Identifier: EclipseLink, version: Eclipse Persistence Services - 2.1.2.v20101 206-r8635 The order of SQL is NOT the same as the sequence of calling EntityManager.persist() if @GeneratedValue(strategy=GenerationType.IDENTITY) has been defined for the Entity. The order of SQL is verified by observing the console log after setting eclipselink.logging.level=FINE. Reproducible: Always Steps to Reproduce: 1. Create an Entity (TestAudit in this case) whose @Id has @GeneratedValue(strategy=GenerationType.IDENTITY) 2. Get an EntityManager and persist a list of entities in order: UserTransaction ut = (UserTransaction) context.lookup("java:comp/UserTransaction"); ut.begin(); EntityManager em = ... testAudit = new TestAudit(); testAudit.setValue("1 "+d); em.persist(testAudit); testAudit = new TestAudit(); testAudit.setValue("2 "+d); em.persist(testAudit); testAudit = new TestAudit(); testAudit.setValue("3 "+d); em.persist(testAudit); testAudit = new TestAudit(); testAudit.setValue("4 "+d); em.persist(testAudit); testAudit = new TestAudit(); testAudit.setValue("5 "+d); em.persist(testAudit); ut.commit(); 3. After committing the transaction, it is found that the order of the final insert SQLs into the database is NOT the same as the order of calling em.persist(testAudit). (Refer to attached eclipseLink.log)
Created attachment 200498 [details] The Entity source
Created attachment 200499 [details] The JSP to reproduce the issue
Created attachment 200500 [details] The server log with eclipselink.logging.level=FINE
EclipseLink does not guarantee the order of inserts (and I doubt other JPA tools do either) JPA provides the flush() operation that allows you to send queries to the database as required.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink