Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 353287 - The order of SQL is NOT the same as the sequence of calling EntityManager.persist()
Summary: The order of SQL is NOT the same as the sequence of calling EntityManager.per...
Status: CLOSED INVALID
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-28 04:33 EDT by geo.temp CLA
Modified: 2022-06-09 10:05 EDT (History)
2 users (show)

See Also:


Attachments
The Entity source (1.24 KB, text/plain)
2011-07-28 04:34 EDT, geo.temp CLA
no flags Details
The JSP to reproduce the issue (1.11 KB, text/plain)
2011-07-28 04:36 EDT, geo.temp CLA
no flags Details
The server log with eclipselink.logging.level=FINE (2.52 KB, text/plain)
2011-07-28 04:37 EDT, geo.temp CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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