JPA 2.0 with Hibernate in NetBeans 6.9

NetBeans 6.9 does not allow to configure Hibernate as JPA 2.0 persistence provider out of the box. Only Hibernate(JPA 1.0) is in the list of providers when setting up a persistence unit. You must create a custom persistence library (Hibernate 3.5+) for JPA 2.0, see Bug 183327 for further info. Unfortunately bundled repositories do not always have recent version of Hibernate available – at the moment of writing the Central Repository has only 3.5.3, while the latest is 3.5.4, thus more tweaking needed. Here is the walkthrough:

1) Add jBoss Releases repository to the NetBeans Maven repository list. Use Window/Other/Maven Repository Browser to open repositories window. When adding new repository use the following URLs:

Repository URL: https://repository.jboss.org/nexus/content/repositories/releases/

Index URL: https://repository.jboss.org/nexus/content/repositories/releases/.index/

2) Add hibernate-entitymanager dependency to your project libraries (right-click on Libraries in Project window to activate context menu). Use

GroupId: org.hibernate
ArtifactId: hibernate-entitymanager
Version: you decide, I use latest, which is 3.5.4 now

The first two steps allows to setup dependencies and to download latest versions of Hibernate libraries. Now you may proceed with custom persistence library setup.

3) Either open existing persistence.xml (if you want to change provider) or create new one (right-click on your project, New/Persistence Unit) and select New Persistence Library from Persistence Provider drop down list. You must add the following libraries:

hibernate-entitymanager/3.5.4-Final/hibernate-entitymanager-3.5.4-Final.jar
hibernate-annotations/3.5.4-Final/hibernate-annotations-3.5.4-Final.jar
hibernate-commons-annotations/3.2.0.Final/hibernate-commons-annotations-3.2.0.Final.jar
hibernate-core/3.5.4-Final/hibernate-core-3.5.4-Final.jar
hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.0.Final/hibernate-jpa-2.0-api-1.0.0.Final.jar

All paths are relative to local repository (usually ~/.m2) and I assume that Hibernate version is 3.5.4. Submit the New Persistence Library form and now you may select Hibernate(JPA 2.0) from the provider list.

4) (optional) Now you have all dependencies in pom.xml and the libraries are available through your local Maven repository. However the pom.xml will not work on another computer, because it does not provide any info on jBoss repository. You may add the following code to your pom.xml to fix this issue:


<repositories>
...
 <repository>
    <id>jboss-public-repository-group</id>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public/</url>
    <layout>default</layout>
    <releases>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
    </releases>
    <snapshots>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
    </snapshots>
 </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
      <id>jboss-public-repository-group</id>
      <name>JBoss Public Repository Group</name>
      <url>http://repository.jboss.org/nexus/content/groups/public/</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
</pluginRepositories>

This entry was posted in Java and tagged , , . Bookmark the permalink.

3 Responses to JPA 2.0 with Hibernate in NetBeans 6.9

  1. Dan says:

    Hi,
    I am trying to follow your description but I don’t understand:
    Where are these in the library context menu?

    GroupId: org.hibernate
    ArtifactId: hibernate-entitymanager
    Version:

  2. Pingback: Jay

  3. Pingback: max

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>