Java Reference
In-Depth Information
hibernate.connection.datasource=java:/comp/env/jdbc/TestDB
hibernate.connection.username=dbuser
hibernate.connection.password=dbpassword
hibernate.jndi.url=t3://localhost:7001
hibernate.jndi.class=weblogic.jndi.WLInitialContextFactory
Typically only the mandatory datasource property is needed.
The Session Factory
You use the Hibernate session factory to create Session objects that manage connection data,
caching, and mappings. Your application is responsible for managing the session factory. You
should only have one session factory unless you are using Hibernate to connect to two or
more database instances with different settings, in which case you should still have one ses-
sion factory for each database instance.
In order to maintain backward compatibility with Hibernate 2, the Hibernate 3 session
factory can also create org.hibernate.classic.Session session objects. These “classic” session
objects implement all of the Hibernate 3 session functionality in addition to the deprecated
Hibernate 2 session methods. We briefly discuss the changes in core functionality between
Hibernate 2 and 3 in Appendix D.
You obtain a session from the SessionFactory object using one of the four openSession()
methods. The no-argument openSession() method opens a session, with the database con-
nection and interceptor specified in the SessionFactory 's original configuration. You can
explicitly pass a JDBC connection to use, a Hibernate interceptor, or both as arguments to the
remaining openSession() methods.
public org.hibernate.classic.Session openSession()
throws HibernateException
public org.hibernate.classic.Session openSession(Interceptor interceptor)
throws HibernateException
public org.hibernate.classic.Session openSession(
Connection connection,
Interceptor interceptor)
public org.hibernate.classic.Session openSession()
throws HibernateException
We discuss Hibernate interceptors in Appendix A. You can also retrieve metadata and
statistics from the SessionFactory .
The other important method on the session factory is close() . The close() method
releases all the resource information used by the session factory and made available to the
Session objects. It is therefore important that any related Session objects have been closed
before invoking this to close the session factory.
Search WWH ::




Custom Search