Hibernate - Envers:是否可以使用SQL触发器创建修订版

时间:2017-04-24 14:40:30

标签: java hibernate triggers hibernate-envers

我希望Envers不要创建修订但只检索它们,使用触发器的速度要快得多。

有没有办法将Envers设置为'只读' ?

1 个答案:

答案 0 :(得分:0)

Is there a way to set Envers to 'read-only' ?

Yes, you essentially need to override the EnversIntegrator so that it does not register the standard Envers listeners with Hibernate ORM, thus effectively causing Envers not to store any revision data during transaction commits.

use of triggers is much faster imho

I think speed isn't the only thing you should be considering here.

The first question is can you replicate all behavior in a series of triggers that mimic the behavior that the Envers listeners do in order to be compliant with the Envers Query API?

For simple entities that maintain no audited relationships, this will probably be somewhat trivial so long as your triggers are written to work with whatever audit strategy you elect to you. For more complex entities where you have audited relationships, I suspect your triggers will be considerably more difficult to write and handle all use cases.

What concerns me by this is the technical debt it brings.

The problem is that upgrades to newer releases become significantly more tedious. You'll have to review the source for each upgraded version to make sure no decisions in your triggers need to be altered to remain compliant with the Query API.

Do you have any benchmarks that show that a comparable trigger-based solution is in fact faster than what Envers listeners do today?