简体   繁体   English

是否值得使用 Hibernate 字节码增强机制?

[英]Is it worth using the Hibernate Bytecode Enhancement mechanism?

I'm currently reading Vlad Mihalcea's book High-Performance Java Persistence .我目前正在阅读 Vlad Mihalcea 的书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.在 Bytecode Enhancement 部分,据说enableDirtyTracking可以通过替换反射来优化大量数据的性能。 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:在对 Hibernate 文档进行进一步研究时,我发现了另外三个属性:

  • enableLazyInitialization , enableLazyInitialization ,
  • enableAssociationManagement , enableAssociationManagement
  • enableExtendedEnhancement . 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?如果我理解正确, enableAssociationManagement使双向关系的独立处理变得多余,并替换了enableLazyInitialization ,如enableDirtyTracking Reflections?

Unfortunately, I couldn't find anything about enableExtendedEnhancement .不幸的是,我找不到任何关于enableExtendedEnhancement的信息。 That's why I have the same question as above.这就是为什么我有与上面相同的问题。 Should I just use it?我应该只使用它吗? Or which disadvantages result from it?或者它会导致哪些缺点?

The enableAssociationManagement only works from parent to child entities, not the other way around. enableAssociationManagement仅适用于父实体到子实体,反之则不行。 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 . enableLazyInitialization可用于惰性属性,例如延迟获取父端@OneToOne关联,因为默认情况下,即使设置为FetchType.LAZY急切地获取该关联。

The enableDirtyTracking setting is not needed if you make sure the Persistence Context never loads too many entities.如果您确保 Persistence Context 从不加载太多实体,则不需要enableDirtyTracking设置。 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. enableExtendedEnhancement设置允许您扩展的不仅仅是实体类,因此字节码增强甚至可以在实体上调用 getter 和 setter 之外发挥作用。 This setting is not recommended.不建议使用此设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM