![]() | ![]() | ![]() |
| |||||||
![]() | ||||||||||
![]() | ![]() | |||||||||
Resin 3.1 Documentation Examples Changes Overview Installation Configuration Quercus SOA/IoC JSP Servlets and Filters Admin (JMX) EJB Amber Security Performance Hessian XML and XSLT Third-party Troubleshooting/FAQ IDE's Scottit Groovy SwiftMQ OpenJMS Hibernate Database |
HibernateHibernate now provides a JCA interface in its beta release. To configure it, use the following: <web-app xmlns="http://caucho.com/ns/resin"> <resource jndi-name="java:comp/env/hibernate"> <type>net.sf.hibernate.jca.ManagedConnectionFactoryImpl</type> <init> <dialect>net.sf.hibernate.sql.MySQLDialect</dialect> <driver-class>org.gjt.mm.mysql.Driver</driver-class> <connection-url>jdbc:mysql://localhost:3306/test</connection-url> </init> </resource> </web-app> Unfortunately, Hibernate's JCA interface does not yet allow
configuration of a JDBC Using the Hibernate session factory uses a similar pattern to the JDBC
package example; import java.io.*; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Session; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.naming.Context; import javax.naming.InitialContext; public class TestServlet extends HttpServlet { private SessionFactory _hibernateFactory; /** * Load and cache the hibernate factory at startup. */ public void init() throws ServletException { try { Context ic = new InitialContext(); _hibernateFactory = ic.lookup("java:comp/env/hibernate"); } catch (Exception e) { throw new ServletException(e); } } public void service(...) throws ServletException { net.sf.hibernate.Session hSession; try { hSession = _hibernateFactory.openSession(); ... } finally { hSession.close(); } } }
|