quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

Support manipulation of the Hibernate-Envers' Change detection

Open HeroxHeruxum opened this issue 2 years ago • 4 comments

Description

I've recently encountered an Issue where Hibernate detected changes where none should have been declared. More preciese: There were ZonedDateTime Values that created unneeded changes. An example I've tried to merge an ZonedDateTime in UTC to an DataBase which is configured to persist values in another TimeZone than UTC. This has to do with Quarkus relying on using the Byte Code Enhancement of Envers. Since Those will load the Initial Value In EU/Berlin for example and comapre it to the value in UTC. Thus it missmatches.

To make it work i had to directly address those the generated Bytecode functions which would have made my code fairly un readable and relient on updates not renaming those methods

I know Its kinda an edge Case/ Bug(?)

Implementation ideas

-provide readable methods for manipulation of the Hibernate Envers change detection

HeroxHeruxum avatar Sep 09 '22 18:09 HeroxHeruxum

/cc @Sanne, @gsmet, @yrodiere

quarkus-bot[bot] avatar Sep 09 '22 18:09 quarkus-bot[bot]

Hi @HeroxHeruxum. This sounds more like a bug than an enhancement request? Could you provide a reproducer, please?

yrodiere avatar Sep 12 '22 06:09 yrodiere

I currently dont have an example on hand @yrodiere, but i should be able to create one given time.

Just to clarify the Interceptor, does get triggered and also does execute its logic correctly. But the whole difference calculation does not get applied when Hibernate is configured to run in byte-code enhancement mode. As explained here http://devdoc.net/javaweb/hibernate/Hibernate-5.1.0/userGuide/en-US/html/ch03.html under point 3.1.2.

The Documentation of quarkus states: "Hibernate ORM in Quarkus relies on compile-time bytecode enhancements to your entities." https://quarkus.io/guides/hibernate-orm

Which in return means any Logging interceptor that would manipulate the difference calculation will not work.

The only way of achieving manipulation of the stored changes, is now only possible via those Functions that will be added to your code during runtime.

HeroxHeruxum avatar Sep 16 '22 18:09 HeroxHeruxum

To me there are two separate issues here:

  1. The fact that ORM or Envers wrongly determines that there is a change because of some (artificial) timezone change.
  2. The fact that you don't get to change the state in onFlushDirty because bytecode enhancement is enabled.

The first could be considered as a bug (but I'd need a reproducer), and if fixed, could make the second issue irrelevant.

The second is indeed documented as expected when bytecode enhancement is enabled, so that would indeed be closer to an enhancement or feature request, be it only to document the limitation directly in the javadoc of Interceptor. I wonder if you've considered alternatives, though, such as JPA entity listeners (@PreUpdate/...).

By the way, a more recent version of the documentation you linked: https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#BytecodeEnhancement-dirty-tracking

Which in return means any Logging interceptor that would manipulate the difference calculation will not work.

I find it highly suspicious that a logging interceptor would change the data being logged. Side-effects are certainly not something I'd expect from a logging system :) I understand there are other, perhaps more legitimate use cases, though. (Such as setting a "last modified date/time").

yrodiere avatar Sep 19 '22 12:09 yrodiere

Even setting a "last modified" timestamp isn't something done typically in an interceptor; I agree it's not the right time to make changes to the model. We have standard JPA callbacks for that, e.g. @PreUpdate - or EntityListeners.

Sanne avatar Sep 23 '22 09:09 Sanne

Hey @HeroxHeruxum , any news on that reproducer for the following problem?

The fact that ORM or Envers wrongly determines that there is a change because of some (artificial) timezone change.

Thanks.

yrodiere avatar Oct 26 '22 07:10 yrodiere

Closing as we never got a reproducer

geoand avatar Dec 01 '22 13:12 geoand