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.

Jacky
  • 8,619
  • 7
  • 36
  • 40
  • 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. – Chris Jun 16 '16 at 17:49
  • 1
    Thanks Chris. I filed a bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=496702. But it seams no one reply on this. – Jacky Jun 29 '16 at 08:18

0 Answers0