Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 505
Deepak Singhal Avatar asked May 31 '12 16:05

Deepak Singhal


1 Answers

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.

like image 87
digitaljoel Avatar answered Oct 25 '22 21:10

digitaljoel