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

Not to turn this into a Hibernate versus Eclipselink thread, but given that the JPA spec does not
specify the ordering behavior you are seeking (since it apparently is not relevant to the core
JPA requirments) you have NO guarantee that Hibernate will perform as you wish in future
versions. You don't even know if it will perform as you wish against a different database vendor or
if the wind is blowing from the north instead of the south on a given day, etc.

On Thu, Jan 17, 2013 at 4:19 AM, Deyan Tsvetanov <deyan@xxxxxxxxxxxx> wrote:
Hi guys, 

I am experiencing a weird imho behaviour of Eclipselink and I'd really like to hear some other opinions . 

I have a pretty simple entity with assigned IDs; 

@Entity @Table(name="ROLE")
public class Role implements Serializable {

private static final long serialVersionUID = 1L;


@Id @Column(name="ID", length=20, nullable=false)
    public String id;

   

}


I am executing the following operations: 

public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("EclipseLinkJPATest");

EntityManager em = emf.createEntityManager();

em.getTransaction().begin();
for (int i = 0; i < 10; i++) {
Role r = new Role();
r.id = "TEST" + i;
em.persist(r);
}
em.getTransaction().commit();

em.close();
emf.close();
}

And I'd expect that the INSERT queries will be executed in the same order as the persist() method is called: 
TEST0, TEST1, TEST2 , etc.

But in the real life the insert queries are in a random order every time: 

EL Fine]: sql: 2013-01-17 12:13:58.11--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST1]
[EL Fine]: sql: 2013-01-17 12:13:58.113--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST6]
[EL Fine]: sql: 2013-01-17 12:13:58.114--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST2]
[EL Fine]: sql: 2013-01-17 12:13:58.115--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST7]
[EL Fine]: sql: 2013-01-17 12:13:58.117--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST4]
[EL Fine]: sql: 2013-01-17 12:13:58.121--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST8]
[EL Fine]: sql: 2013-01-17 12:13:58.123--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST3]
[EL Fine]: sql: 2013-01-17 12:13:58.124--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST9]
[EL Fine]: sql: 2013-01-17 12:13:58.126--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST5]
[EL Fine]: sql: 2013-01-17 12:13:58.127--ClientSession(1694665796)--Connection(1795160456)--INSERT INTO ROLE (ID) VALUES (?)
bind => [TEST0]

As you can see the order if insert queries is: 
TEST1, TEST6, TEST2, TEST7, TEST4, etc. 


That is really weird and wrong ! :) 
I dug a lot and could not find a solution. 

Please help :)

Thanks in advance,
Deyan 


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users