Question

I'm made a small test project using Java EE 7 and Hibernate 4.2.2 and Glassfish 4.

Here are my pom.xml (web)

 <dependencies>        
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>br.com.myproject</groupId>
        <artifactId>escola-ejb</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

ejb

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>
<!--Hibernate-->     
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.2.2.Final</version>
    <scope>compile</scope>
</dependency>

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.2.2.Final</version>
        <scope>compile</scope>
</dependency>

It has only one entity called Student. And some crud page with list, create and edit. I can compile and deploy but when I try to open the list list page (all pages where generated by netbeans 7.3.1 with the option generate JSF pages from entity models), I got an error:

A system exception occurred during an invocation on EJB StudentFacade, method: public java.util.List br.com.myproject.ejb.facade.AbstractFacade.findRange(int[]).
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
    at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:698)
    at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)

(...)

If I change the persistence.xml to to Eclipse link it works fine. But I rollback to hibernate. I got this error.

I've googled a lot but I'm not able to find any information as the Java EE 7 is a new technology.

Was it helpful?

Solution

Hibernate 4.2.2 is compatible with JPA 2.0. Glassfish 4 and EE 7 comes with JPA 2.1. For that you need Hibernate 4.3.0.Beta1 or later.

It might work with earlier versions of Hibernate but you will most likely run into problems. I would recommend to wait until they release a 4.3 final version of Hibernate.

OTHER TIPS

Simply adding Hibernate as a dependency to your application won't work. You either have to add the Hibernate JARs to GlassFish's server classpath (in which case Hibernate would be available as a JPA provider for all applications), or you bundle the Hibernate JARs in the lib directory of an EAR (in which case only that application would use Hibernate). See this blog for an example of the later case: http://javafromthetrenches.wordpress.com/2011/01/15/using-hibernate-jpa-with-glassfish/

You don't need to do anything special to use JTA and an EclipseLink (or Hibernate) datasource. Session beans are automatically transactional, so inject an entity manager instance into your session bean and use it from the business methods.

I should also point out that you'll need to add JDBC resources to GlassFish if you're not using the default Java DB database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top