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
Related
I have a project which uses the latest version of Hibernate (let's say v2.0). I'm using it all around the project. But my project also uses some dependency (let's say MySQL Connector), which uses Hibernate (let's say v1.0). So in my pom.xml I would have something like:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.mysql</groupId>
<artifactId>MySQLConnector</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
In the end, when I compile my project, the version of Hibernate downloaded and used is v1.0 because MySQLConnector needs this one. Is there a way to specify some version of a dependency that will be used only by one of my dependencies and the rest of the code to use another version? So something like:
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.mysql</groupId>
<artifactId>MySQLConnector</artifactId>
<version>3.7</version>
<somemagicaltag>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>1.0</version>
</somemagicaltag>
</dependency>
</dependencies>
Thus allowing MySQLConnector to use the older version of Hibernate if it likes it, but the rest of my code to use the newer, more updated version of Hibernate?
Is there a way to specify some version of a dependency that will be
used only by one of my dependencies and the rest of the code to use
another version?
No. There can be only one. So in your case either 1.0 or 2.0 (usually using newer version makes more sense). Which version is used depends on the order of dependencies in pom.xml which use such transitive dependency: Why order of Maven dependencies matter?
You can also define which version will be used by specifying such dependency (this overrides transitive dependency version) or by defining such dependency either in dependencyManagement tag: Differences between dependencyManagement and dependencies in Maven or by using BOM mechanism: Maven BOM [Bill Of Materials] Dependency
In all "normal" cases, the dependency that you declare wins against the ones that come transitively. So I would assume that in your setup, you get version 2 of hibernate (and nothing else). You can find out by calling mvn dependency:list.
You cannot load the same class twice in different versions, so normally, you cannot have two versions of hibernate in the same project. There are approaches around this (using the Maven shade plugin), but this should be the exception. Try to make your own code and your dependencies work with the same version of hibernate.
You can skip downloading that default artifact which is getting downloaded by Maven.
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.mysql</groupId>
<artifactId>MySQLConnector</artifactId>
<version>3.7</version>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>org.hibernate</groupId>
<artifactId>Hibernate</artifact>
</exclusion>
</exclusions>
</dependency>
</dependencies>
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)
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!
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.
In my Maven pom.xml I have the following dependencies:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.0.0.ga</version>
</dependency>
If I look at the Maven dependencies I find that hibernate-entitymanager depends on hibernate-3.2.6.ga.
Is this correct? Why would it not depend on a 3.3.x version of Hibernate? Does this mean I am using a hybrid 3.2/3.3 version of Hibernate?
Also, I am pulling my dependencies from repo1.maven.org -- should I instead be using repository.jboss.org? For example, repository.jboss.org has a newer version of hibernate-validator.
The versions of the hibernate components are to a large degree independent of one another. v3.x of component A doesn't necessarily go with v3.x of component B.
This link shows the dependencies between the various components. This confirms that Entity Manager 3.3.2 has a dependency of 3.2.x of Hibernate Core. If you want to use Hibernate Core 3.3.x, you need to use Entity Manager 3.4.0.