Hibernate

From Resin 3.0

Revision as of 00:56, 30 November 2007 by Ferg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Hibernate with the JPA (EntityManager) interface requires Resin 3.1.4 or later.

You will need to copy the jars from both hibernate and hibernate-entitymanager. The persistence.xml in META-INF/persistence.xml will need to specify the HibernatePersistence provider, e.g.

 <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
   <persistence-unit name="test">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <jta-data-source>jdbc/database</jta-data-source>

    <properties>
       <property name="hibernate.transaction.manager_lookup_class"
           value="org.hibernate.transaction.ResinTransactionManagerLookup"/>
    </properties>
 </persistence>

Your servlet or WebBean can use @In EntityManagerFactory (or @Named("test") or @PersistenceUnit(unitName="test")) to get the EntityManager

import javax.persistence.*;
import javax.transaction.*;
import javax.webbeans.*;

public class MyServlet extends GenericServlet {
   @Named("test") EntityManagerFactory _factory;
   @In UserTransaction _ut;

    ...
 }
Personal tools