JSP 1.2 tag library for Hibernate 2.1

Managing the session factory

The taglibs uses JNDI to find the SessionFactory. By default, it will lookup at java:comp/env/hibernate/SessionFactory. This is where Hibernate binds the SessionFactory ordinarily.

Normally I create the Hibernate Configuration and this automatically binds the Session Factory to JNDI in the correct place. However, Tomcat's JNDI is read-only, so this Hibernate docs page might help: Using Hibernate with Tomcat and JNDI. It is also useful for anyone having trouble setting up Hibernate using JNDI.

If you have configured Hibernate to bind the session factory at a different location, you can set a different default for the tags in web.xml. Set a servlet context init parameter named com.lokitech.hibtags.sessionFactory to the location you want, for example, hibernate/SomeOtherSessionFactory.

All tags that require a session (most tags) take an optional sessionFactory attribute that allows you to specify an alternate JNDI location. If instead you want to use a session factory bound at java:comp/env/hibernate/SpecialSessionFactory, you could do the following:

<hib:load var="foo" class="bar" value="${id}" sessionFactory="hibernate/SpecialSessionFactory" />

The <hib:session> tag allows you to declare when to open and close a session. Any tags that are used within this block will use this session.

If you use a tag outside of a <hib:session> block, it will automatically open and close a session for you.

Mailing list
About Us
SF page

SourceForge.net Is Down