How to configure a single Hibernate SessionFactory for multiple web applications

I have n number of web applications talking to a single database using hibernate. I need to configure JBOSS in such a way that there will be single Hibernate SessionFactory and the web applications will use this SessionFactory to obtain Sessions. Which is the best optimal way to acheive this solution?
Who is Participating?
jboss (starting from jboss 4.0.2) provides special mbean which will provide hibernate session factory.
you could check it in jboss documentation
Basically you need to create xml file in deploy folder of jboss:
something like:
<mbean code="org.jboss.hibernate.jmx.Hibernate"
    <attribute name="DatasourceName">java:/DefaultDS</attribute>
    <attribute name="Dialect">
    <attribute name="SessionFactoryName">
Just point it to correct database ds jndi URL (I used defaultDS which will use HSQLDb)
and after that you can lookup sessionfactory using JNDI lookups from your code:

InitialContext ctx      = new InitialContext();
SessionFactory factory  = (SessionFactory)
Session        hsession = factory.openSession();
everything depends in implementation of your web application. How do you call sessionfactory inside your web app? Do you use Spring? do you use EJB3 ?
for Spring there is a some discussion which is available at
visu_nekkAuthor Commented:
We are using a combination of Struts with Hibernate.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.