Harder Than it Should be - Hibernate Maven POM Dependencies
Join the DZone community and get the full member experience.
Join For FreeIn preparation for my upcoming No Fluff Just Stuff session in Cincinnati, I decided to finally rework the code example to use Hibernate as the JPA provider - rather than using OpenJPA. Don't get me wrong, OpenJPA is a great persistence framework. However it has fewer features and is less widely supported than Hibernate.
One of the things I wanted to add to the 'Enterprise JPA' session was to show some reuse of JPA persistent objects with other frameworks, specifically, Grails. Grails is my favorite web development platform now-a-days, and it is built on top of Hibernate and Spring. I already use Spring heavily in the JPA sessions' demo code, and being able to reuse the JPA PC's with Grails would make for an awesome demo, and also show a real-world value add in using JPA.
Grails doesn't support "generic" JPA yet, though it's on the roadmap. Frankly, I don't think Grails should attempt to support JPA until JPA 2.0 hits the streets - it would just be too much work to bridge JPA 1.0 to the dynamic queries that Grails supports now with Hibernate - for the sake of 6 months when JPA 2.0 will be out. Of course, in my sessions I remind attendees that to do real work, you have to use JPA implementation specific extensions anyways (just like Grails does to do many of the cool things GORM provides).
Using OpenJPA in a Maven 2 based project was so simple - just add the OpenJPA dependency in the pom.xml and that's basically it! It loads all the OpenJPA dependencies all by itself, and everything just worked. Initially, I thought that putting in Hibernate support would be just as easy. Unfortunately, it wasn't - I finally broke down and deciphered the Hibernate Compatibility Matrix and got it all put together. Even with the matrix handy, it still took some trial and error. In the hopes of saving somebody else some angst getting a pom.xml with Hibernate dependencies working, I've included the one that worked for me below.
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>CallTracker</groupId>
<artifactId>JPA</artifactId>
<name>CallTracker</name>
<version>1.0</version>
<description>Tracks Conference Calls </description>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.3-603.jdbc4</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.ga</version>
</dependency>
<dependency>
<groupId>geronimo-spec</groupId>
<artifactId>geronimo-spec-jta</artifactId>
<version>1.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.0.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.2.GA</version>
</dependency>
</dependencies>
</project>
Opinions expressed by DZone contributors are their own.
Comments