Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worth using the Hibernate Bytecode Enhancement mechanism?

I'm currently reading Vlad Mihalcea's book High-Performance Java Persistence.

In the Bytecode Enhancement section, it is said that enableDirtyTracking can optimize performance with large amounts of data through replacing reflections. But I'm just wondering if there are any disadvantages?

Unfortunately, I couldn't find any or only very old information.

<plugin>
   <groupId>org.hibernate.orm.tooling</groupId>
   <artifactId>hibernate-enhance-maven-plugin</artifactId>
   <version>${hibernate.version}</version>
   <executions>
      <execution>
         <configuration>
            <failOnError>true</failOnError>
            <enableDirtyTracking>true</enableDirtyTracking>
            <enableLazyInitialization>false</enableLazyInitialization>
            <enableAssociationManagement>false</enableAssociationManagement>
            <enableExtendedEnhancement>false</enableExtendedEnhancement>
         </configuration>
         <goals>
            <goal>enhance</goal>
         </goals>
      </execution>
   </executions>
</plugin>

And while doing further research in the Hibernate documentation I came across three more properties:

  • enableLazyInitialization,
  • enableAssociationManagement,
  • enableExtendedEnhancement.

But I can't find much about it on the internet.

If I understood it correctly, enableAssociationManagement makes the independent handling of bidirectional relationships superfluous and replaces enableLazyInitialization like enableDirtyTracking Reflections?

Unfortunately, I couldn't find anything about enableExtendedEnhancement. That's why I have the same question as above. Should I just use it? Or which disadvantages result from it?

like image 690
Sven M. Avatar asked Nov 09 '19 18:11

Sven M.


1 Answers

The enableAssociationManagement only works from parent to child entities, not the other way around. So, it's not very useful. Better synchronize both ends of a bidirectional association using add/remove methods.

The enableLazyInitialization can be useful for lazy attributes, like fetching a parent-side @OneToOne association lazily, as by default, this one is fetched eagerly even when set to FetchType.LAZY.

The enableDirtyTracking setting is not needed if you make sure the Persistence Context never loads too many entities. You are better off reducing the Persistence Context size than using this setting.

The enableExtendedEnhancement setting allow a you to extends more than the entity classes, so bytecode enhancement can work even beyond calling getters and setters on entities. This setting is not recommended.

like image 183
Vlad Mihalcea Avatar answered Nov 10 '22 00:11

Vlad Mihalcea