spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Additional Hibernate properties are not recognized

Open mdoninger opened this issue 11 years ago • 3 comments

I have the following problem:

I have defined the property spring.jpa.hibernate.transaction.jta.platform in my application.properties. However, when the HibernateJpaAutoConfiguration starts, it gets the properties by a call to JpaProperties#getHibernateProperties(), which itself calls Hibernate#getAdditionalProperties(). But in this method, a new Map is created and two properties added (ejb.naming_strategy and hbm2ddl.auto) and all existing properties are discarded. Thus the auto configuration tries to configure the JTA platform, which fails (because we use Hibernate 4.2).

Is this type of property handling intended or is this a bug, meaning that also all existing properties should be in the map which is returned by Hibernate#getAdditionalProperties()?

mdoninger avatar Jan 13 '15 15:01 mdoninger

Is that a custom Hibernate property? If so, the correct prefix for the provider custom properties is spring.jta.properties

snicoll avatar Jan 13 '15 16:01 snicoll

I also tried with that, but in that case it doesn't matter, because the method HibernateJpaAutoConfiguration#customizeVendorProperties only gets the map with the 2 properties i mentioned). So either the if clause which checks for the JTA platform property is wrong or the method which returns the Hibernate properties.

mdoninger avatar Jan 13 '15 16:01 mdoninger

I actually noticed this too.

If you put a breakpoint at the return of getVendorProperties(), then you'll see the map doesn't contain user defined hibernate properties. It will only contain, like previously mentioned, either only ejb.naming_strategy or ejb.naming_strategy and hbm2ddl.auto, so max of 2 properties.

I believe this happens because in getAdditionalProperties method ofJpaProperties class, the passed in Map<String, String> existing is not merged (putAll) with the newly instantiated map Map<String, String> result. It simply returns only the result map and that is used in getVendorProperties of HibernateJpaAutoConfiguration. The user defined properties are valid and are picked up in the actuator if you go /configprops and look at the spring.jpa.CONFIGURATION_PROPERTIES.

drumonii avatar Jan 13 '15 19:01 drumonii