使用历史记录策略或DescriptorEventAdapter时禁用eclipselink批量写入

时间:2016-06-16 02:00:19

标签: jdbc eclipselink history

我尝试使用eclipselink历史记录策略来记录一个表/实体的更改历史记录。我还使用DescriptorEventAdapter / aboutToInsert,aboutToUpdate,aboutToDelete钩子来插入审计记录。除了我在应用上述功能后发现批量写入选项不起作用外,所有事情都运行良好。

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

代码如下:

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

当我禁用history / DescriptorEventAdapter时,sql就像:

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]

应用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]
你能提出一些建议吗?提前谢谢。

0 个答案:

没有答案