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

If you want to know the order in which the rows were inserted I use @OrderColumn (eg. in combinantion with INDEX(..) function in a JPQL for example).

I think that EclipseLink can choose the order in which it commits the entities to the database... (I haven't read the JPA spec so this is an assumption)

Wim


On Thu, Jan 17, 2013 at 12:09 PM, Deyan Tsvetanov <deyan@xxxxxxxxxxxx> wrote:
Hibernate persists the entities in the correct order: 

2:57:58,867 TRACE TypeFactory:72 - Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@395fa2b5
Hibernate: insert into ROLE (ID) values (?)
12:57:59,365 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST0
Hibernate: insert into ROLE (ID) values (?)
12:57:59,369 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST1
Hibernate: insert into ROLE (ID) values (?)
12:57:59,371 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST2
Hibernate: insert into ROLE (ID) values (?)
12:57:59,372 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST3
Hibernate: insert into ROLE (ID) values (?)
12:57:59,373 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST4
Hibernate: insert into ROLE (ID) values (?)
12:57:59,375 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST5
Hibernate: insert into ROLE (ID) values (?)
12:57:59,376 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST6
Hibernate: insert into ROLE (ID) values (?)
12:57:59,377 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST7
Hibernate: insert into ROLE (ID) values (?)
12:57:59,378 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST8
Hibernate: insert into ROLE (ID) values (?)
12:57:59,380 TRACE BasicBinder:83 - binding parameter [1] as [VARCHAR] - TEST9



On Jan 17, 2013, at 12:19 , 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