Hibernate version: 3.2.6
application server : bea weblogic 9.2.
database server : oracle 9i
Configuration file:
<hibernate-configuration>
<session-factory name="IPRUHA_SESSIONFACTORY">
<property name="connection.datasource">IPRUHA</property>
<property name="connection.username">weblogic</property>
<property name="connection.password">weblogic</property>
<!--Dialect for Oracle-->
<property name="dialect">org.hibernate.dialect.Oracle9iDialect</property>
<!--Echo all executed SQL to stdout-->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name ="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="current_session_context_class">jta</property>
</session-factory>
</hibernate-configuration>
code to look up session factory
1]
Code:
private static final Properties JNDI_ENV_PROPERTIES = new Properties();
static {
JNDI_ENV_PROPERTIES.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
}
2] code using JNDI template to lookup object Code:
SessionFactory sf = null;
IJndiOperations jndiOperation=new JndiTemplate(JNDI_ENV_PROPERTIES);
Object obj=null;
try{
obj=jndiOperation.lookUp(sessionFactoryId);
}catch(NamingException nameEx){
logger.error("in " + MN + " [ Exception occured of type :- "
+ nameEx.getClass().getName() + " message :- "
+ nameEx.getMessage() + " ]");
throw new TechnicalException(nameEx, nameEx.getMessage());
}
3] JNDI TEMPLATECode:
package com.ipru.ha.admin.common.jndi;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
/**
* This class provide implementation for <code>IJndiOperations</code>
*
* @author Team Patni < polganes >
* @since Aug 1, 2008
*
*/
public class JndiTemplate implements IJndiOperations {
private static Logger logger=Logger.getLogger(JndiTemplate.class.getName());
private Properties environment ;
/**
*
*/
public JndiTemplate(Properties environment) {
this.environment=environment;
}
[b]/**
* Returns new instance of <code>InitialContext</code>
*
* @return new instance of <code>InitialContext</code>
* @throws NamingException
*/
private Context getContext()throws NamingException{
final String MN="getContext()";
Context context=null;
try{
context=new InitialContext(this.environment);
}catch(NamingException nameEx){
logger.error("in "+MN+" [ exception occured of type :- "+nameEx.getClass().getName()+" message :- "+nameEx.getMessage());
throw nameEx;
}
return context;
} [/b]
/**
* @return Returns the environment.
*/
public Properties getEnvironment() {
return environment;
}
/* (non-Javadoc)
* @see com.ipru.ha.admin.common.jndi.IJndiOperations#bind(java.lang.String, java.lang.Object)
*/
public void bind(String key, Object obj)throws NamingException{
this.getContext().bind(key,obj);
}
/* (non-Javadoc)
* @see com.ipru.ha.admin.common.jndi.IJndiOperations#reBind(java.lang.String, java.lang.Object)
*/
public void reBind(String key, Object obj) throws NamingException {
this.getContext().rebind(key,obj);
}
[color=red]/* (non-Javadoc)
* @see com.ipru.ha.admin.common.jndi.IJndiOperations#lookUp(java.lang.String)
*/
public Object lookUp(String key) throws NamingException {
return this.getContext().lookup(key);
}[/color]
}
problem
consider following scenario
my application server started
my application load configuration from xml file
in weblogic console JNDI tree i can able to see Sessionfactory object bound
i can able to perform hibernate operations
now my server kept idle for few minutes lets say 1 hour
after one hour some one made request
now in this case i am not able to look up (i.e. got session factory object null)