0

Based on new information, I am rephrasing my question, keeping the original text below for reference:

When switching to Hibernate 6, I got requirements for new packages to include. I do not understand why those packages are needed, so I need further information what they do. Doing a search on Google or Stack Overflow mostly ends with "just add the package".

Questions (see below for answers):

  • Why is hibernate-validator needed in Hibernate 6, but not in Hibernate 5?
  • Why is hibernate-core-jakarta needed instead of hibernate-core?
  • Why is jakarta.el-api needed?

Original Text:

I am using functionality as specified by JPA with Hibernate as implementation. Thus, I am including jakarta.persistence-api and jakarta.validation-api, as well as the required Hibernate packages.

Up to version 5.6.10, including hibernate-core-jakarta seemed to be the right thing to do. Using that package, everything worked out-of-the-box.

I have now switched to Hibernate 6.1.2. Here, hibernate-core-jakarta does not exist anymore. Thus, I am including hibernate-core now. Based on error messages I got, I also added hibernate-validator 7.0.5.Final and jakarta.el-api 5.0.1.

Now, things seem to work. Still, I am wondering: Why was hibernate-core-jakarta removed? Is the solution I found the correct one, or is there a hidden problem now?

Edit: based on some more things I read I can probably better phrase what is puzzling me:

  • As far as I know, Hibernate was originally a library independent of JPA. Then it was adapted to implement the JPA standard. (Please correct me if I am wrong.)
  • I thought using the hibernate-core-jakarta package was the equivalent to "use JPA compatibility" and hibernate-core was the equivalent to "use only Hibernate".
  • Now I think that maybe hibernate-core-jakarta meant "use JPA from Jakarta" and hibernate-core meant "use old JPA from Java EE" (javax).
  • This, of course means that now Java EE is no longer supported and thus hibernate-core inherited the functionality from hibernate-core-jakarta!?
  • However, if that is true, why did I start needing additional libraries when moving on to the new version?
Tim Lammarsch
  • 161
  • 1
  • 1
  • 10
  • Does this answer your question? [why is dependency to javax.persistence-api removed in hibernate-core 6.0.2](https://stackoverflow.com/questions/72475572/why-is-dependency-to-javax-persistence-api-removed-in-hibernate-core-6-0-2) – MWiesner Aug 26 '22 at 15:28
  • 1
    Thank you for giving me pointers - I am happy that not all people are anonymous downvoters. That posting is about switching from javax.persistence-api to jakarta.persistence-api. I already had used them before, but perhaps that is actually the right hint I need to understand what is happening. I am going to edit my question. – Tim Lammarsch Aug 26 '22 at 16:01
  • What Maven artifact are you referring to? `hibernate-core` does **not** depend on `hibernate-validator` regardless of the version. – Piotr P. Karwasz Aug 27 '22 at 12:21
  • The moment I switch from implementation group: `'org.hibernate', name: 'hibernate-core-jakarta', version: '5.6.10.Final'` to implementation group: `'org.hibernate', name: 'hibernate-core', version: '6.1.2.Final'` using Gradle I get `INFO: Error calling 'jakarta.validation.Validation#buildDefaultValidatorFactory' jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.` – Tim Lammarsch Aug 27 '22 at 12:42

2 Answers2

2

You can look/debug into org.hibernate.cfg.beanvalidation.BeanValidationIntegrator to understand why bean validation was activated for your application and hence requires an implementation to be available. Usually, the implementation is only required when the API is available on the class path, so if you don't want to use jakarta.validation, just make sure it's not part of your dependencies.

jakarta.el-api is then a transitive requirement of jakarta.validation, so it seems the root of your issue is that you somehow have a dependency on the validation api.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • 1
    I marked the post as solution to give credit for the fact that it contained the right hint that `jakarta.validation` caused the need for `hibernate-validator`. Anybody who reads this might want to read my full summary in my answer to my own post. – Tim Lammarsch Sep 04 '22 at 12:29
0

Why is hibernate-core-jakarta needed instead of hibernate-core?

Hibernate 5 is still written using Java Persistence API from Java EE (javax.*). There is an alternative already using Jakarta Persistence API (jakarta.*). I used this alternative because I already used Jakarta.

Hibernate 6 made Jakarta the default, so the new hibernate-core is the direct successor of hibernate-core-jakarta and the old hibernate-core is discontinued.

Why is hibernate-validator needed in Hibernate 6, but not in Hibernate 5?

I am still not sure why it only started with Hibernate 6, but the requirement of hibernate-validator stems from the including of jakarta.validation. I am doing mark-up with @NotNull and this is what originally caused it.

Why is jakarta.el-api needed?

I have been switching between Unit tests and the growing application in an unorganized way. jakarta.el-api is needed when Hibernate is used in Unit tests. Thus, I sometimes needed it, sometimes I did not. Moreover, it is not enough. You also need an implementation for the API. Choosing the right implementation is based on your project. here is a great overview.

Apparently, you can also disable this part of the code. However, the answer still relies on the javax version, and I could not reproduce it.

Tim Lammarsch
  • 161
  • 1
  • 1
  • 10