15 July 2011

NetBeans, Hibernate and JPA2

When you create a new persistence unit in a standalone NetBeans project, it only proposes Hibernate with JPA1.
This is because NetBeans bundles an old Hibernate release.
To work with Hibernate/JPA2, download a recent Hibernate (>= 3.5) and SLF4J (same version as the one used in your hibernate download).
Add a new persistence library with these jars from the hibernate installation directory:

  • hibernate3.jar
  • jars from lib/jpa folder
  • jars from lib/required folder
  • an SLF4J implementation library from the SLF4J download, e.g. slf4j-jdk14-1.6.1.jar
    • if you are using ehcache there is no need to download SLF4J separately. It bundles  slf4j-jdk14-1.6.1.jar.
NetBeans (>= 6.9) will recognize the library as a Hibernate/JPA2 provider.