Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 353287

Summary: The order of SQL is NOT the same as the sequence of calling EntityManager.persist()
Product: z_Archived Reporter: geo.temp
Component: EclipselinkAssignee: Project Inbox <eclipselink.orm-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: geo.temp, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
The Entity source
none
The JSP to reproduce the issue
none
The server log with eclipselink.logging.level=FINE none

Description geo.temp CLA 2011-07-28 04:33:13 EDT
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)
Comment 1 geo.temp CLA 2011-07-28 04:34:12 EDT
Created attachment 200498 [details]
The Entity source
Comment 2 geo.temp CLA 2011-07-28 04:36:32 EDT
Created attachment 200499 [details]
The JSP to reproduce the issue
Comment 3 geo.temp CLA 2011-07-28 04:37:24 EDT
Created attachment 200500 [details]
The server log with eclipselink.logging.level=FINE
Comment 4 Tom Ware CLA 2011-08-02 09:14:50 EDT
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.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:05:47 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink