Hibernate
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

IDE's
Scottit
Groovy
PHP
Code Libraries
JMS
JCA Resources
JMX
SSL Accelerators

Hibernate
JCA Resources
JCA Resources
JMX

Hibernate

Hibernate now provides a JCA interface in its beta release. To configure it, use the following:

web.xml
<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 DataSource, so you can't yet take advantage of Resin's pooling.

Using the Hibernate session factory uses a similar pattern to the JDBC DataSource. Like JDBC Connections, you must close the Hibernate session in a finally block.

TestServlet
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();
    }
  }
}


JCA Resources
JCA Resources
JMX
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.