Hibernate JPA how to configure dynamic-update in persistence.xml

China☆狼群 提交于 2019-12-06 05:29:03

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10837584/hibernate-jpa-how-to-configure-dynamic-update-in-persistence-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!