I’m a maven noob. Wanted to integrate Hibernate 3 and JPA into a Maven 2 project. Not really into the hibernate maven plugin (anybody have good/bad experiences with it?) because I’m actually superstitious and like to control things myself, so I decided to integrate manually. After a little bit of trial and error and updating the JBoss maven repository here’s a sample pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.resteasy</groupId> <artifactId>titan-cruise</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>titan-cruise</name> <url>http://maven.apache.org</url> <repositories> <repository> <id>jboss</id> <url>http://repository.jboss.org/maven2</url> </repository> </repositories> <dependencies> <dependency> <groupId>hibernate</groupId> <artifactId>hibernate3</artifactId> <version>3.2.4.SP1</version> </dependency> <dependency> <groupId>hibernate-annotations</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.3.0.GA</version> </dependency> <dependency> <groupId>hibernate-commons-annotations</groupId> <artifactId>hibernate-commons-annotations</artifactId> <version>3.0.0.GA</version> </dependency> <dependency> <groupId>hibernate-entitymanager</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.3.1.GA</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.7</version> </dependency> <dependency> <groupId>hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>1.8.0.2</version> </dependency> <dependency> <groupId>jboss</groupId> <artifactId>jboss-common-core</artifactId> <version>2.2.0.GA</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.0.jboss</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.6.0.GA</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.1_3</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project>
Jan 07, 2008 @ 19:38:32
Well if the hibernate-entitymanager would be configured like the one on mvnrepository.com you would also get persistence-api and could leave out a lot of dependencies and only add them if you really need a specific version (annotations or in general hibernate). Furthermore I prefer either a parent pom with version extracted or at least in the same pom. Like
[3.3.1.GA,)
Jan 07, 2008 @ 22:43:19
Thanks for the Maven lesson. I’ll have to figure out WTF that means now… 🙂
Jan 08, 2008 @ 13:00:38
damn of course I meant (forgot the code tag)
[3.3.1.GA,)
and in your dependencies like
hibernate-entitymanager
hibernate-entitymanager
${hibernate-em.version}
Jan 08, 2008 @ 13:06:45
(Pls remove previous comment)
[3.3.1.GA,)
hibernate-entitymanager
hibernate-entitymanager
${hibernate-em.version}
(A Preview mode would be very helpful sometimes 😉 )
The version range simply defines minimum 3.3.1.GA or better.
Jan 08, 2008 @ 13:16:54
WTF
just imagine those are xml tags 🙂
properties
hibernate-em.version
(3.3.1.GA,]
hibernate-em.version
properties
and your dependency looks like
dependency
groupId
hibernate-entitymanager
groupId
artifactId
hibernate-entitymanager
artifactId
version
${hibernate-em.version}
version
dependency
Hopefully this time it works.
Jan 08, 2008 @ 17:33:16
There’s an example of extracting the versions into properties in the JBoss EJB3 Parent Build:
http://anonsvn.jboss.org/repos/jbossas/projects/ejb3/trunk/build/pom.xml
…this way, all versions are together at the top, and will be consistent among all children of the parent (subproject POMs will not designate a version number).
S,
ALR
Jan 15, 2008 @ 09:30:06
Hi Bill,
You might want to give a look at the Maven dependency mechanism documentation:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
It mentions transitive dependencies, which are very important to get right in order for maven to work properly.
You also might want to give a look at Mavenizer, a little tool I have created which helps in mavenizing third party libraries. It handles transitive dependencies:
http://mavenizer.sourceforge.net/
Kind regards,
Cédric
Feb 01, 2008 @ 22:37:02
I suffered also when I tried it first until I found that a nice guy in codehaus is maintaining a POM.
So now I have only:
>dependencies<
>dependency<
>groupId<junit>/groupId<
>artifactId<junit>/artifactId<
>version<3.8.1>/version<
>scope<test>/scope<
>/dependency<
>dependency<
>groupId<org.codehaus.mojo.hibernate3>/groupId<
>artifactId<maven-hibernate3-jdk15>/artifactId<
>version<2.0-alpha-1>/version<
>/dependency<
>dependency<
>groupId<org.apache.derby>/groupId<
>artifactId<derby>/artifactId<
>version<10.2.2.0>/version<
>/dependency<
>/dependencies<
I used JavaDB and so build a JUnit test that can run without container.
The code full runnable code is here, and the blog entry here.
May 15, 2010 @ 21:51:42
Thanks, this blog aided me somewhat in narrowing down some issues with the latest version, Why do they always seem to leave out vital documentation when they release a new version? It may be trivial to them but not to me. I’m sure we’re not alone.