Announcement Announcement Module
No announcement yet.
SLSB, DAO and hibernateSessionFactory management Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SLSB, DAO and hibernateSessionFactory management


    Can someone please help me out here: We have SLSB CMT and our SLSBs are deferring their business logic to a pojo (using the spring abstract ejb convenience class).

    Our hibernate session factory has so far been setup using a jboss sar file and deployed as such making the hibernate session factory available via a JNDI call.

    After implementing the business pojo, I am trying to get the daoImpl (also injected)'s baseclass, 'HibernateBaseDAO', to hold onto the hibernate session factory and return a session for each request. But the factory is null when I try to use it in my daoImpl. (I have defined an init-method in the bean definition so that the factory can be set via a jndi-call. I have also tried using the JndiObjectFactoryBean):

    <bean id="hibernateFactory" class="org.springframework.jndi.JndiObjectFactoryB ean" singleton="true">
    <property name="jndiName" value="java:/cbs/hibernate/HibernateFactory"/>
    <bean id="hibernateSessionFactoryInit" class="" init-method="init" singleton="false">
    <property name="factory" ref="hibernateFactory"/>

    HibernateBaseDAO :
    private static SessionFactory factory;
    protected static final String HIBERNATE_FACTORY = "java:/cbs/hibernate/HibernateFactory";

    public void init(){
    log.debug("init: begin!");
    System.out.println("init: begin!");
    InitialContext initialContext = new InitialContext();
    factory = (SessionFactory) initialContext.lookup(HIBERNATE_FACTORY);
    System.out.println("init: factory = :" + factory + ":!");
    catch (Exception e)
    log.error("Exception getting datasource: "+e);
    System.out.println("init: end!");
    log.debug("init: end!");

    * @param factory The factory to set.
    public static void setFactory(SessionFactory factory) {
    HibernateDAO.factory = factory;

    Am I missing something obvious here? The factory appears in the jndi-tree as shown in the jmx-console. Also is there a perhaps a better way to do this?

    Any help is much appreciated.

  • #2
    Why is the 'factory' property declared static? Does the setup for JndiObjectFactoryBean really work? I'm missing the setting of the 'proxyInterface' property?
    Perhaps a better way is to use the ContextSingletonBeanFactoryLocator (see Spring reference documentation).


    • #3
      Same error...

      I'm seeing the same error. If anyone finds a fix for this problem please post!

      with hibernate 3.0.1, spring 1.2.1, and jboss 4.0.2:

      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is javax.naming.NamingException: JNDI object with [java:/hibernate/AuctionSessionFactory] not found: JNDI implementation returned null
      javax.naming.NamingException: JNDI object with [java:/hibernate/AuctionSessionFactory] not found: JNDI implementation returned null
      at org.springframework.jndi.JndiTemplate$1.doInContex t(
      at org.springframework.jndi.JndiTemplate.execute(Jndi
      at org.springframework.jndi.JndiTemplate.lookup(JndiT
      at org.springframework.jndi.JndiLocatorSupport.lookup (
      at org.springframework.jndi.JndiObjectLocator.lookup(
      at org.springframework.jndi.JndiObjectFactoryBean.aft erPropertiesSet(


      • #4
        I would try to replace the static property and direct lookup with dependency injection.
        You can use org.springframework.jndi.JndiObjectFactoryBean for that purpose. When setting the property lookupOnStartup of this factory bean to false, access should be deferred until the first usage. This is normally sufficent to keep things working.