5
votes

I am trying to deploy a JAR file in a GlassFishv3 server. This results in the error:

com.sun.enterprise.admin.cli.CommandException: 
remote failure: 
Exception while preparing the app : 
java.lang.RuntimeException:
java.lang.ClassNotFoundException: 
org.hibernate.ejb.HibernatePersistence

I thought that the class "org.hibernate.ejb.HibernatePersistence" is missing and tried to add libraries containing it to the folder "glassfish\domains\domain1\lib". I took them from my NetBeans folder "NetBeans 6.9\java\modules\ext\hibernate". The result is, that glassfish is not starting any longer. It runs into a timeout. The last log entry is

INFO|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName=Thread-1;|{felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = C:\glassfishv301\glassfish\domains\domain1\autodeploy\bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = C:\DOKUME~1\me\LOKALE~1\Temp\fileinstall-8074722487477598658, felix.fileinstall.filter = null}|#]

The autodeploy\bundles folder mentioned in that entry is empty.

Any idea how to move formard?

3

3 Answers

4
votes

If you want to use Hibernate as the JPA provider, my advice would be to install the Hibernate JPA module via the GlassFish v3 Update Center:

alt text http://a.yfrog.com/img80/5218/screenshot009z.png

The other way would be to package Hibernate EntityManager inside your application. Didn't experiment this though.

2
votes

And for the record, the command-line version to add the Hibernate package is :

bin/pkg install hibernate
0
votes

Integration Hibernate-JTA-JPA-EJB-GlassFish-MySQL: 1- Hibernate-JPA-EJB-GlassFish-MySql: This guidance is for integrating hibernate.4.3.5 and EJB and GlassFish.4.0 in NetBeans.8.0 IDE. Create a web project in net beans and add hibernate jar files to the project,other setting related to configuring MySql and glassfish is very simple so I do not describe in this article then create persistence.xml file as follow :

<persistence-unit name="omidashouriPU" transaction-type="Resource_Local">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/YourSchemaName"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="yourpassword"/>
            <property name="hibernate.show_sql" value="true"/>
    </properties>
</persistence-unit>

In Your EJB class (class that annotated with @Stateless) for creating EntityManager use following syntax :

EntityManagerFactory emf = Persistence.createEntityManagerFactory("omidashouriPU"); EntityManager em = emf.createEntityManager(); em = emf.createEntityManager(); em.getTransaction().begin(); em.persist(YourEntityObject); em.getTransaction().end();

As you Know when you are using “transaction-type="Resource_Local", you have to manage the transaction by yourself, mean that, managing of opening and closing the transaction is our responsibility.

2- Hibernate-JPA-JTA-EJB-GlassFish-MySql: This guidance is for integrating hibernate.4.3.5 and EJB and JTA and GlassFish.4.0 in NetBeans.8.0 IDE. Create a web project in net beans (attention: do not make web project with maven because there is a bug in Netbeans.8.0 IDE ) and add hibernate jar files to the project, other setting related to configuring MySql and glassfish is very simple(Just define Connection Pool and JDBC in Resources>JDBC:JDBC Connection Pools & JDBC Resources, guidance for that is in the web if you search for it)(attention: for defining a correct JNDI, first create a temporary project which depends on JNDI like JPA project in glassfish, then copy the settings that is created in Glassfish for this Project because there is a bug in glassfish when you are going to get a ping to MySQl in creating your first Connection Pool if you create it by yourself inside the glassfish) so I do not describe in this article then create persistence.xml file as follow :

<persistence-unit name="omidashouriPU" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/yourJNDI (which you defined in glassfish) </jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/YourSchemaName"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="yourpassword"/>
            <property name="hibernate.show_sql" value="true"/>
    </properties>
  </persistence-unit>

In Your EJB class (class that annotated with @Stateless) for creating EntityManager use following syntax :

@PersistenceContext(unitName = " omidashouriPU ")
EntityManager em;
em.persist(YourEntityObject);

As you Know when you are using “transaction-type="JTA", management of transaction is not with you, mean that, managing of opening and closing the transaction is application server (Here GlassFish) responsibility. Indeed if you check your persistence.xml in mode design, in front of persistence provider drop down box you can see hibernate is now added.

Dear Reader, I had Spend 3 days for solving this problem, please add your experience to this article in order that complete it, for any question you can send me email at [email protected] .