jim
Nov 11th, 2005, 12:00 PM
Hi
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):
</snippet>
<bean id="hibernateFactory" class="org.springframework.jndi.JndiObjectFactoryBean" singleton="true">
<property name="jndiName" value="java:/cbs/hibernate/HibernateFactory"/>
</bean>
<bean id="hibernateSessionFactoryInit" class="uk.co.mycom.cbs.dao.HibernateDAO" init-method="init" singleton="false">
<property name="factory" ref="hibernateFactory"/>
</bean>
</snippet>
HibernateBaseDAO :
<snippet>
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!");
try{
InitialContext initialContext = new InitialContext();
factory = (SessionFactory) initialContext.lookup(HIBERNATE_FACTORY);
System.out.println("init: factory = :" + factory + ":!");
initialContext.close();
}
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;
}
</snippet>
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.
Jim
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):
</snippet>
<bean id="hibernateFactory" class="org.springframework.jndi.JndiObjectFactoryBean" singleton="true">
<property name="jndiName" value="java:/cbs/hibernate/HibernateFactory"/>
</bean>
<bean id="hibernateSessionFactoryInit" class="uk.co.mycom.cbs.dao.HibernateDAO" init-method="init" singleton="false">
<property name="factory" ref="hibernateFactory"/>
</bean>
</snippet>
HibernateBaseDAO :
<snippet>
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!");
try{
InitialContext initialContext = new InitialContext();
factory = (SessionFactory) initialContext.lookup(HIBERNATE_FACTORY);
System.out.println("init: factory = :" + factory + ":!");
initialContext.close();
}
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;
}
</snippet>
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.
Jim