-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to Hibernate 5.1 #2763
Comments
With a pure JPA-based implementation, it looks like we don't have to do anything. Let's reopen if we think we need to change something. |
Actually, Hibernate 5 has a breaking change regarding the naming strategy support so we should at least track that. |
The new naming strategy seems to create a regression as documented here: Maybe due to this deprecated call:
|
Hibernate 5 brings a breaking change by setting the `hibernate.id.new_generator_mappings` property to `true` by default. This does not use a sequence for a `Long` PK and therefore any SQL not providing a value for the primary key will break. Also, Hibernate 5 changed its naming strategy API so we'll have to detect that in `JpaProperties#Hibernate` and set the appropriate value. See spring-projectsgh-2763
I've tested with spring boot 1.3.0.RC1 and I still get the same warning. Also, when autogenerating tables I see each row two times for each table, maybe there is something suboptimal there too?
|
What worries me is using a naming strategy that will change when that problem will be fixed, and hence render uncompatible the autogenerated schema |
I think the main problem is that the Hibernate team has no concrete answer for that either. If you look at the naming strategy we have for 4.3, it's basically If you are relying on that naming strategy (with the little fix that we have added in |
I tried to use Hibernate5 with Then I removed all the Jadira stuff and tried to start to app. Bang. The problem is that the https://jira.spring.io/browse/DATAJPA-777 Hibernate5 now uses two types of naming strategies ( @Bean
@Primary
public static JpaProperties jpaProperties() {
final Map<String, String> hibernateConfig = newHashMap();
hibernateConfig.put("hibernate.implicit_naming_strategy",
"org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl");
hibernateConfig.put("hibernate.physical_naming_strategy",
"com.anyapp.CustomNamingStrategy");
final JpaProperties jpaProperties = new JpaProperties();
jpaProperties.setProperties(hibernateConfig);
jpaProperties.setDatabase(ORACLE);
jpaProperties.setDatabasePlatform(ORACLE12C_DIALECT);
jpaProperties.setGenerateDdl(false);
jpaProperties.setShowSql(false);
return jpaProperties;
} Therefore I am loosing The most annoying part was to find out which naming strategies to apply in what way and the fact that I had to implement The custom naming strategy is nearly the same as here... The Hope this helps getting Hibernate5 compat into 1.3. Another helper may be: |
Thanks for the detailed analysis. We know about the naming strategy (see the comments before yours). I am not sure I understand why you have tot hack @Bean
@Primary
@ConfigurationProperties(prefix = "spring.jpa")
public static JpaProperties jpaProperties() {
...
} |
I overwrote the bean in order to be able to specify the new naming strategy key names:
As I understand, they would not be applied by If I can achieve that from |
Well either do what I wrote above (have you seen it?) or ditch your override and add this to your config spring:
jpa:
properties:
hibernate.implicit_naming_strategy: xyz
hibernate.physical_naming_strategy: abc |
That works. Thats a lot. |
This commit updates our test suite to be able to run on both Hibernate 4 and Hibernate 5. Two important changes made this change necessary: * Spring Boot no longer provides a naming strategy for Hibernate 5 so it defaults to the one provided by Hibernate. The main difference is the physical name that is provided for camel case properties * If the `@GeneratedValue` uses the `AUTO` strategy, Hibernate 5 uses sequence by default. This commit forces the strategy to `IDENTITY` in order to be compliant with what Hibernate 4 does by default See spring-projectsgh-2763
I've added a proposal in ca023b5 (which is mainly dealing with the naming strategy) and I've also extended the support by "fixing" our test suite to work also with Hibernate 5 (see f3c3119). If you take the state of that branch you can build with Most of these changes are due to the naming strategy change. Maybe we shouldn't rely on default column names after all? |
Upgrade to Hibernate 5.1, whilst still retaining compatibility with Hibernate 4.3. This commit introduces the following changes: * Add SpringPhysicalNamingStrategy to provides lowercase/underscore table names support. This should be equivalent to the previous SpringNamingStrategy that was used with Hibernate 4. No ImplicitNamingStrategy is provided since the Hibernate 5 defaults appear to be roughly equivalent to the conventions used in Spring Boot 1.3 spring.jpa.hibernate.naming. * Migrate `spring.jpa.hibernate.naming-strategy` to `spring.jpa.hibernate.naming.strategy` and provide additional properties for physical and implicit. * Add `spring.jpa.hibernate.use-new-id-generator-mappings` property and default to `false` when on Hibernate 5 to retain back compatibility. See gh-2763
Add a sample showing how Hibernate 4 can be used if necessary. See gh-2763
I think this is basically fixed but I'm leaving it open for team discussion and because we'll need some release notes. The plan is:
|
I like @philwebb's plan. We're already using Hibernate 5.1 due to bug with 4.3's component path naming strategy that is fixed in 5.1. This will make us upgrading to boot 1.4 easily. And we always use the component-path physical naming strategy anyway. |
We need to not deprecate |
I tried to upgrade to spring boot 1.4.0M2 my app that is using 1.3.x where I was already using hibernate5 but a new naming strategy was adopted and all my tables were modified (and of course everything stopped working). |
@Polve check the release notes I am not sure I understand what you mean here. Upgrading to Spring Boot will not modify your tables. We didn't support Hibernate 5 previously so if you were specifying an implicit or physical strategy before, you should have done so in your own code. The alternative is that you were using Hibernate 5 default and those breaks compared to what you can experience with Boot and Hibernate 4.3. The easiest way to know which properties are available is to use the auto-completion in your IDE or check the appendix. |
But the problem I'm having is exactly that by upgrading from Hibernate 5.1+spring boot 1.3 to hibernate 5.1+spring boot 1.4M2 the naming strategy changed substantially and a field named "twoWords" is now mapped to "two_words", breaking havoc on the application. I understand this is related to the new physical-strategy and implicit-strategy handling, the problem being that I'm unable to find any documentation on what are the correct values for those fields to restore the old behaviour (the default used in boot 1.3). |
@Polve I think there is a misunderstanding of what the issue is. You were using Hibernate 5 before we actually support it so you got the default Hibernate 5 provides. These breaks compared to Hibernate 4 with Spring Boot. What we did is making sure that those who are upgrading can do so safely (If you take Hibernate 4 and Spring Boot, you'll get If you want to stick with the default Hibernate 5 provides, just configure the naming strategy accordingly:
Just to make that clear, this is the hibernate 5 default that you got by using it before we actually support it. It's not something that we changed, we didn't support it before. I hope that clarifies. |
@snicoll https://docs.spring.io/spring-boot/docs/1.4.0.M2/reference/html/common-application-properties.html states:
which means the default physical strategy is empty, which should mean Hibernate's default, not Spring Boot's. If Spring Boot 1.4 specifies a physical strategy, the appendix should mention it to be clear. Same goes for Hibernate4's naming.strategy, since Spring Boot specifies the So even if the behavior is "by design", I think there's a documentation bug here. |
Thanks @snicoll for the details: that was exactly what I was looking for. I agree with @ceefour : I got confused because I thought I was using hibernate's default, that's why by already using hibernate 5.1 on boot 1.3 I expected to work the same way with boot 1.4. Thanks to both for the valuable infos. |
@ceefour we can't document everything in the appendix. There is an algorithm to figure out what to do there and it's documented in the release notes. Granted, we should add that to the doc but simply putting the value in the appendix does not reflect what's happening either. Please don't use the appendix to attempt to figure out what happens.
There are many places where we compute the default based on the environment and we can't write "a default " because it simply does not exist. Don't take the shortcut of no-value in the appendix == no default. |
@snicoll After reading the release notes I guess the behavior is the following as Spring Boot's defaults:
Other properties mention their defaults, e.g.:
I don't understand why Spring Boot's naming strategy defaults can't be mentioned in the appendix. Leaving it empty as it is now is even more confusing. |
No it's not. I think I already explained why above so I am afraid I am out of arguments here. We only set the latter if you're running Hibernate 4 (otherwise it's not set at all). The former is only set if you haven't set it any other way (including via |
For reference, this commit updates the documentation. I've also updated the release notes based on your feedback. |
Is there a way for a user to apply the SpringNamingStrategy in SpringBoot 1.3.x with latest Hibernate so as to have it already compatible when upgrading to 1.4.x? Does adding spring.jpa.hibernate.naming.strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy work for 1.3.x? |
No it doesn't, that file is compiling against the Hibernate 5 API. The whole point of that effort is that migrating from Hibernate 4 (1.3) to Hibernate 5 (1.4) is painless if you're using our naming strategy. Have you actually noticed that's not compatible? |
We want to use hibernate 5 with spring boot 1.3.x and want to have the same naming as hibernate 4.3 as 1.4.x isn't available and don't want to run into any issues when upgrading to 1.4.x. |
We don't officially support H5 in 1.3.x so I am afraid I have nothing to suggest. You could copy the naming strategies but you'll need to setup that manually in 1.3.x. |
Thanks. That's sufficient :) |
On a related note, you may be interested in adding something about this to the docs: Using |
Spring Framework 4.2 will add support for Hibernate 5 which will lead to auto-configuration updates on our side.
The text was updated successfully, but these errors were encountered: