Hibernate JPA如何在persistence.xml中配置动态更新 [英] Hibernate JPA how to configure dynamic-update in persistence.xml

查看:161
本文介绍了Hibernate JPA如何在persistence.xml中配置动态更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在我的Java源代码中配置可完成的操作,如:

  @ org.hibernate.annotations .Entity(
dynamicUpdate = true)

因为我希望它是可配置的。 p>

我没有使用hibernate.properties,只使用persistence.xml,因为我使用的是JPA。对于使用 persistence.xml dynamicUpdate 作为 true $ c> only?

解决方案

您在Hibernate实现中使用JPA标准。在这种情况下,您正试图配置特定于Hibernate实现的东西,而不是JPA标准的一部分。如果它是一个帮助配置实现的属性,那么其中的很多可以通过persistence.xml传递给实现,但在这种情况下,如果您试图为每个实体配置属性,那么您将不得不这样做休眠方式。你可能已经看过这个问题与Bozho非常类似的答案。



所有这些,如果您决定继续使用org.hibernate。*注释进行配置,你不会真的能够配置它,因为注解值必须是常量表达式。



一个有趣的解决方案是启动监听器中的某些东西,它可以修改所有的持久性类并添加属性。您可以读取配置的值并使用此问题答案中介绍的机制进行设置。

I do NOT want to configure in my java source code which can be done like:

@org.hibernate.annotations.Entity(
        dynamicUpdate = true) 

because I want it to be configurable.

I am not using hibernate.properties, only persistence.xml as I am using JPA. How can I make dynamicUpdate as true for all entities using persistence.xml only?

解决方案

You are using the JPA standard with the Hibernate implementation. In this case, you are attempting to configure something that is specific to the Hibernate implementation and not a part of the JPA standard. If it's a property that helps configure the implementation, then many of those can be passed to the implementation through persistence.xml, but in this case where you are attempting to configure the property for each entity, you are going to have to do it the Hibernate way. You've probably seen this question with a very similar answer by Bozho.

With all that, if you decide to go ahead with org.hibernate.* annotations for configuration, you won't really be able to make it configurable because annotation values must be constant expressions.

One interesting solution would be something in a startup listener that would modify all the persistent classes and add the attribute. You could read the configured value and set it using the mechanism described in the answer to this question.

这篇关于Hibernate JPA如何在persistence.xml中配置动态更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆