eclipselink batch write is disabled when use history policy or DescriptorEventAdapter
Asked Answered
F

0

4

I try to use eclipselink history policy to record the change history of one table/entity. I also use DescriptorEventAdapter/aboutToInsert,aboutToUpdate,aboutToDelete hooks to insert audit record. All things works well except that I found the batch-writing option did not work after I apply the features above.

<property name="eclipselink.jdbc.batch-writing" value="JDBC" />

The code is like:

for (int i = 0; i <= 3; i++) {
    MyEntity e= new MyEntity ();
    e.setName("insert-" + i);
    entityManager.save(e);
}

When I disable history/DescriptorEventAdapter, the sql is like:

DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY (ID, NAME) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [1, insert-0]
DEBUG o.e.p.s./.sql -   bind => [2, insert-1] 
DEBUG o.e.p.s./.sql -   bind => [3, insert-2]
DEBUG o.e.p.s./.sql -   bind => [4, insert-3]

After apply the history/DescriptorEventAdapter

DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY (ID, NAME) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [1, insert-0]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY_HIST (ID, NAME, VALID_FROM) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [1, insert-0, 2016-06-16 01:55:22.424]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY (ID, NAME) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [2, insert-1]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY_HIST (ID, NAME, VALID_FROM) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [2, insert-1, 2016-06-16 01:55:22.424]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY (ID, NAME) VALUES (?, ?) 
DEBUG o.e.p.s./.sql -   bind => [3, insert-3]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY_HIST (ID, NAME, VALID_FROM) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [3, insert-3, 2016-06-16 01:55:22.424]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY (ID, NAME) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [4, insert-3]
DEBUG o.e.p.s./.sql - INSERT INTO MY_ENTITY_HIST (ID, NAME, VALID_FROM) VALUES (?, ?)
DEBUG o.e.p.s./.sql -   bind => [4, insert-3, 2016-06-16 01:55:22.424]

Could you please give some suggestion this? Thanks in advance.

Freesia answered 16/6, 2016 at 2:0 Comment(2)
EclipseLink seems to immediately flush the entity insert so it can then issue the history insert. You will need to file a bug/feature request in EclipseLink so that it can bundle these up more efficiently to take advantage of batch writing.Stateroom
Thanks Chris. I filed a bug bugs.eclipse.org/bugs/show_bug.cgi?id=496702. But it seams no one reply on this.Freesia

© 2022 - 2024 — McMap. All rights reserved.