How to Generate JPA Metamodel classes? (July 2018) - java

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!

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)

Spring Boot throwing autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

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.

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

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

IntelliJ IDEA: How can I make sources of dependent libraries to be available in classpath on compilation?

How can I make sources of dependent libraries to be available in classpath on compilation ?
I'm using IntelliJ IDEA 11.
When I add Global Library to module and artifact IDE never copies sources and javadocs. That makes sense because they are not needed in runtime. But I need them in compile time.
Interestingly though IDEA makes sources available if I add dependency as folder. I guess in this case it doesn't differentiate what sits in that folder. Odd.
Thoughts ?
i solved this issue in maven config by specifying another dependency to hibernate-validator one with sources and one without.
the one with sources i defined:
classifier: sources
scope: provided
EX:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
It's a bug that sources attached to a library are not used on GWT compilation. This bug is fixed in IDEA 11.1 EAP.

Categories