Spring-boot: Provide the necessary dependencies in the JPA starter for it to work on Java 9 and later

Created on 3 Sep 2018  路  12Comments  路  Source: spring-projects/spring-boot

Hibernate requires JAXB that is not provided as it's available out of the box up to Java8. With Java9 there are two options: add the JAXB api or add an additional module. That module is deprecated in Java10 and removed completely in 11 so that the only real option there is to add JAXB.

They were several requests to request initializr to automatically include JAXB when the JPA starter is added but I want to research a fix that is more global first.

enhancement

Most helpful comment

Isn't the underlying issue that Hibernate doesn't work out-of-the-box with recent versions of Java? It seems to me that Hibernate adding the JAXB dependency so it is compatible OOTB is the ideal solution. Adding JAXB to Spring Boot's starter would feel like a temporary solution/workaround until Hibernate does what it IMO should do for Java 9+ compatibility.

All 12 comments

Barring a change of heart when I learn that it's huge, I am in favour of adding the JAXB API to the JPA starter. With the need for it in Java 11 and Java 11 being an LTS release, I think it ought to work out of the box.

Isn't the underlying issue that Hibernate doesn't work out-of-the-box with recent versions of Java? It seems to me that Hibernate adding the JAXB dependency so it is compatible OOTB is the ideal solution. Adding JAXB to Spring Boot's starter would feel like a temporary solution/workaround until Hibernate does what it IMO should do for Java 9+ compatibility.

@shakuzen, @snicoll made the same point to me yesterday and I agree with you both. While we could work around the problem in our starter it would be more elegant if Hibernate itself worked out-of-the-box on Java 11.

@vladmihalcea Are you aware of any plans to address this in Hibernate? Or do you have any pointers to the Hibernate team's recommendation for the optimal manual configuration to use Hibernate on Java 11 without unduly inconveniencing those on Java 8.

@wilkinsona For the moment, Hibernate requires JAXB. Until we switch to something else, the JAXB dependency will have to be provided somehow.

Thanks, @vladmihalcea. Is there an issue we can watch to track "until we switch to something else"?

@wilkinsona For the moment, there is no such issue. You can create a Jira issue and let's see what gets decided about JAXB. I suppose this will be addressed after 6.0 is launched, but it's worth having an issue where we could discuss possible solutions or approaches.

I've opened HHH-12946.

Doesn't the same apply to the web dependencies? When you have an @RestController and expose XML that would break on Java 9 and up as well. Although granted that would probably be less frequent then Hibernate.

It would be at least nice if Spring would provide a managed dependency for JAXB.

Although granted that would probably be less frequent then Hibernate.

That and it's totally optional (i.e. you are requesting to use it).

It would be at least nice if Spring would provide a managed dependency for JAXB.

There is dependency management for JAXB.

Here are some numbers for the size of the Data JPA sample's fat jar:

No additions: 35075234 bytes
With JAXB API: 35200986 bytes
With JAXB runtime: 36739668 bytes

Interestingly, the sample works with just the JAXB API which adds 123KB. The runtime adds a further 1503KB bringing the total increase to 1626KB.

Petclinic also works with just the API.

Given that the API only adds 123KB on top of the existing 30+MB and that it's enough for at least some JPA-based applications to work, I think we should add a dependency on the API to the starter. Until we hear from a significant number of users on Java 11 who also need the JAXB runtime, I don't think adding it for everyone is justified.

Was this page helpful?
0 / 5 - 0 ratings