Spring Boot throwing autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - java

It all started after i included the below in springboots pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Beta2</version>
</dependency>
i am using hibernate validators like #NotNull , then started getting the below errors "datatype source not found", i did follow some of the other stackoverflow q&a where they asked me to include h2 and that added to the mess.
I have my application.properties file where i have configured it for using mongo ?
is there a way to fix it ?

As far as I understand, all you are trying to do is validation.
And for only validation, you do not need to include hibernate-core dependencies.
replace your dependency with
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
version 5.1.3.Final is latest stable release.

Related

org.hibernate.internal.util.xml.XMLHelper.<init>(Lorg/hibernate/boot/registry/classloading/spi/ClassLoaderService but it does not exist

An attempt was made to call the method org.hibernate.internal.util.xml.XMLHelper.(Lorg/hibernate/boot/registry/classloading/spi/ClassLoaderService;)V but it does not exist. Its class, org.hibernate.internal.util.xml.XMLHelper, is available from the following locations:
I had a same situation with following dependencies. And I did this.
Exclude hibernate-envers from spring-data-envers.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>${version.org.springframework.data}</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</exclusion>
</exclusions>
</dependency>
And depends on it directly.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>${version.org.hibernate}</version>
<scope>compile</scope>
</dependency>
I had the same issue migrating from Spring Boot 2.1.3 to 2.1.4,
There are some major changes between Hibernate 5.3 and 5.4, so you need to make sure that all of your dependencies are using this last version.
Solution : update your dependencies to versions using Hibernate 5.4 (In my case I had to update hibernate-jpamodelgen to the last version).
(Maybe you could also use exclusions to prevent your dependencies using the wrong versions : https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html)

How to Generate JPA Metamodel classes? (July 2018)

I have a maven/hibernate/mysql app I'm developing and am having an issue getting the jpa-metamodel stuff working. I have this in my pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.1.Final</version>
<scope>provided</scope>
</dependency>
According to this answer (see 2nd answer down wtih 'March 2018 Answer with Hibernate 5' heading) that addition to the pom.xml and the correct jars on the classpath should be all that are required.
I did a bunch of googling, but most of the answers I came across were old, and I believe deprecated.
Is there a maven goal I need to run especially for the metamodel classes? Does just 'compile' work for these classes?
I also have my compiler settings as follows:
What am I missing?
thanks!

Many jars libraries version compatibiity

For example I have the following hibernate stuff in my pom.xml:
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.10.Final</version>
</dependency>
Now it is working good. But at the moment I need to change version of hibernate core to 5. I am afraid affection of my change. As I understand it is rarity if library has back compatibility. But after changing major version it is absolutely impossible.
How can I determine respective versions of remain hibernate stuff ?
Usually the team (Hibernate in this case) should provide a compatibility matrix of its various libraries.
Even if they don't, it's generally not that difficult to determine that yourself. The latest versions of all the libraries should generally be compatible, so if you intend to upgrade everything to the latest, the upgrade is likely to go smooth.
In your case, hibernate-core, hibernate-envers and hibernate-entitymanager appear to follow the same version nos., so you could use 5.0.0.Beta2 for these libs. Just use the latest versions of the rest of the libraries (almost all of them look like utilities, so I'd expect them to be compatible with the core libs above).
You're going to have to try the combinations to see which one works. In these cases, having a strong set of test suites in place usually helps.
Maven Bill of materials (BOM) provides such a feature where we can include the artifacts which we need, however the versions need not be explicitly defined and the versions would be referred from the bom file which would help maintain the latest versions of the defined artifacts.
More details and examples are provided at this link:
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Another with a JBoss example which I found:
http://www.mastertheboss.com/jboss-frameworks/maven-tutorials/jboss-maven/maven-and-jboss-how-to-use-boms

#FieldMatch cannot be resolved to a type (Spring Framework)

I was trying to use the annotation #FieldMatch in a web application with Spring Framework.
These are the jars i added
but Eclipse tells me "FieldMatch cannot be resolved to a type"; I thought I needed Hibernate jars but I was wrong. What jar i need?
It's in hibernate validator, if you're using maven, add this dependency :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>

How to apply Hibernate patch

I am facing problem running a native SQL query in Hibernate 3.I googled and found its a bug which was fixed in Hibernate 4.1.3. It also has an attachment of a patch file.This is the link:
https://hibernate.onjira.com/browse/HHH-2697
I want to apply that patch to my existing hibernate version.Can anybody suggest how I can achieve that?
Thanks in advance.
Replace the old hibernate jar or maven dependency xml with the new one.
For instance, in maven say you have...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.1</version>
</dependency>
Change this too....
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
</dependency>
Or replace the jar in your build path, you can get the jars from here

Categories