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

Restore support for Hibernate 4.2.x in Boot 1.2

Open mdoninger opened this issue 12 years ago • 16 comments

In the commit 8219f2be4 a dependency on the class org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform was added to HibernateJpaAutoConfiguration, however in Hibernate 4.2.x the package is different: org.hibernate.service.jta.platform.internal.NoJtaPlatform.

Is it intended to remove support for Hibernate 4.2.x with Spring Boot 1.2.0?

mdoninger avatar Aug 28 '14 07:08 mdoninger

Spring Boot has always used and supported Hibernate 4.3.x. I don't think it's right to say that support for 4.2 has been removed as it was never intentionally provided in the first place.

Is there something preventing you from using 4.3?

wilkinsona avatar Aug 28 '14 07:08 wilkinsona

Yeah, WebSphere :(

mdoninger avatar Aug 28 '14 07:08 mdoninger

But on the other hand, in the HibernateEntityManagerCondition there are both Entitymanager classes, from 4.2 and 4.3:

    private static String[] CLASS_NAMES = {
            "org.hibernate.ejb.HibernateEntityManager",
            "org.hibernate.jpa.HibernateEntityManager" };

Shouldn't this condition then only be true, when the class from Hibernate 4.3 is present?

mdoninger avatar Aug 28 '14 07:08 mdoninger

I guess that means we do explicitly support Hibernate 4.2. When Boot was 1.0 I think Spring Data was still on 4.2.

dsyer avatar Aug 28 '14 07:08 dsyer

For the moment i hacked a workaround in my application, but if you want, i can provide a fix for that, so that it works with Hibernate 4.2 (would be my first contribution to Spring Boot, so i'm not sure, if i get it all correct).

mdoninger avatar Aug 28 '14 08:08 mdoninger

Contributions are definitely welcome. If it's the same order of hack as we already have then it's probably acceptable. Read the guidelines in CONTRIBUTING.adoc and make sure you fill in the contributors agreement (link in README).

dsyer avatar Aug 28 '14 08:08 dsyer

I have created a pull request (https://github.com/spring-projects/spring-boot/pull/1476) to disable the HibernateJpaAutoConfiguration for Hibernate 4.2, because otherwise you get NoClassDefFoundErrors. I think, the only way to readd Hibernate 4.2 support would be to create a new module, where we could add Hibernate 4.2 as dependency to compile the auto configuration class. But on the other hand i think it would get out of hand to create modules for every dependency, which introduces such changes between two versions.

Because i have configured the JTA platform with a property, i have just copied the class in my project and removed the customizeVendorProperties as a quick workaround.

mdoninger avatar Aug 31 '14 19:08 mdoninger

Rather than disabling auto-configuration with Hibernate 4.2, would it not be possible to access JtaPlatform.INSTANCE using reflection?

wilkinsona avatar Sep 01 '14 10:09 wilkinsona

The SpringJtaPlatform class also depends on the new package structure (extends AbstractJtaPlatform), so then that would also have to be initialized by reflection. If that's ok for you, i can change that, but i wasn't sure, if that's a good style (well, surely it isn't).

mdoninger avatar Sep 01 '14 11:09 mdoninger

We could drop (or rather fail to add) support for Hibernate 4.2 and JTA? There has to be a fairly clear boundary to the hacks to make them worthwhile.

FWIW this is approximately the same level of hackery we employ to support Tomcat 8 as well as 7. Jetty 9 is not supportable because it gets too convoluted (too many API changes).

dsyer avatar Sep 01 '14 11:09 dsyer

I would be ok with that (hence my patch). I have created a blog post, where i explained my hack, so anyone who has the same problem will sooner or later stumble upon that (http://www.mdoninger.de/2014/08/31/spring-boot-1-2-0-with-Hibernate-4-2/ for anyone who's interested).

mdoninger avatar Sep 01 '14 11:09 mdoninger

I'd recommend declaring Hibernate-JTA auto-configuration as only working on Hibernate 4.3+. If the rest of Boot's Hibernate support keeps working with Hibernate 4.2, that has to be good enough.

jhoeller avatar Sep 01 '14 11:09 jhoeller

Sounds good to me. I was a bit surprised when @mdoninger pointed out that we ever had 4.2 support of any sort

wilkinsona avatar Sep 01 '14 11:09 wilkinsona

The main problem with Hibernate 4.2 vs 4.3 is that the latter is JPA 2.1 based... which means that people on EE 6 servers without a JPA 2.1 API patch can only really use Hibernate 4.2, at least when bootstrapping it through the JPA setup contract. That's the main reason why we'll keep supporting Hibernate 4.2+ for the entire Spring Framework 4.x line, while recommending Hibernate 4.3 these days.

jhoeller avatar Sep 01 '14 11:09 jhoeller

I'll try to implement that with some reflection (i guess i can provide a first pull request on friday or saturday).

mdoninger avatar Sep 03 '14 12:09 mdoninger

I've pushed an implementation, where i load the specific Hibernate related classes with reflection. Please give me some feedback about the error handling, i couldn't find any other classes with a similar behaviour, so i'm not sure, if logging is enough, or if there should be any other actions (like rethrowing exceptions etc.).

mdoninger avatar Sep 14 '14 10:09 mdoninger