我有一个包含hibernate的jboss应用程序(Web服务生产者/消费者)。它正常工作正常。当我的控制器启动时,我初始化休眠并创建一个sessionfactory
。
然后,我在执行各种数据库事务时使用此sessionfactory
生成会话。
我们很好。
我的问题出现在控制器上一段时间不活动之后(比如外部Web服务暂时没有传递任何数据,然后尝试发送一些数据)。看起来我的sessionfactory
已关闭。
dbContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">${jdbc.driverClassName}</prop>
<prop key="hibernate.connection.url">${jdbc.databaseurl}</prop>
<prop key="hibernate.connection.username">${jdbc.username}</prop>
<prop key="hibernate.connection.password">${jdbc.password}</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
</props>
</property>
</bean>
<mvc:interceptors>
<bean class="com.xxxx.interceptor.MyInterceptor" />
</mvc:interceptors>
<bean id="projectDao" class="com.promo.dao.ProjectDaoImpl"/>
<bean id="project" class="com.promo.domain.Project"/>
</beans>
DAO
public class ProjectDaoImpl implements ProjectDao{
@Autowired
SessionFactory sessionFactory;
@Override
public NetworkDetails getNetworkDetails(NetworkInput networkInput) {
Session session = null;
NetworkDetails networkDetails = new NetworkDetails();
try
{
int sizeList = 0;
String networkName = "";
networkName = networkInput.getNetworkName();
networkName = networkName.toUpperCase();
BigDecimal autoPurge = new BigDecimal(0);
BigDecimal PROJECTSILOAssetId = new BigDecimal(0);
BigDecimal dropBoxId = new BigDecimal(0);
StringBuilder hqlQuery = null;
Query query = null;
List<Object[]> networkDetailsList = null;
session = sessionFactory.openSession();
hqlQuery = new StringBuilder();
hqlQuery.append(" SELECT ");
hqlQuery.append(" PROJECT_INSTANCE_URL, ");
hqlQuery.append(" PROJECT_TOKEN, ");
hqlQuery.append(" SEND_MESSAGE_NEW_VERSIONS, ");
hqlQuery.append(" SEND_MESSAGE_CHANGED_VERSION, ");
hqlQuery.append(" HOST_CONTEXT, ");
hqlQuery.append(" AUTO_PURGE_DELAY, ");
hqlQuery.append(" PROJECTSILO_APIKEY, ");
hqlQuery.append(" PROJECTSILO_USERNAME, ");
hqlQuery.append(" PROJECTSILO_PASSWORD, ");
hqlQuery.append(" DROPBOX_TEAMTOKEN, ");
hqlQuery.append(" DROPBOX_ACCOUNTEMAIL, ");
hqlQuery.append(" DROPBOX_TARGETURL, ");
hqlQuery.append(" SEND_MSG_DELIVERED_VERSIONS, ");
hqlQuery.append(" VERSION_AUTO_PURGE, ");
hqlQuery.append(" PROJECTSILO_ASSET_ID, ");
hqlQuery.append(" DROPBOX_SHARED_URL, ");
hqlQuery.append(" DROPBOX_ID ");
hqlQuery.append(" FROM MAPPINGS_MASTER ");
hqlQuery.append(" WHERE ");
hqlQuery.append(" ORGANIZATION_ID IN ( SELECT ORGANIZATION_ID FROM ORGANIZATION WHERE UPPER(ORGANIZATION_NAME) = :networkName AND DELETED_FLAG = 'N' )");
logger.debug("query getNetworkDetails:::---------> " +hqlQuery );
if (session!=null)
{
query = session.createSQLQuery(hqlQuery.toString());
query.setParameter("networkName", networkName);
}
if (query!=null)
{
networkDetailsList = query.list();
}
if ( networkDetailsList!=null){
logger.debug("if loop");
sizeList = networkDetailsList.size();
for(Object[] obj : networkDetailsList){
logger.debug("Inside the for loop in networkDetailsList dao layer");
if (obj[0]!=null)
{
networkDetails.setPROJECT_URL((String)obj[0]);}
else
{
networkDetails.setPROJECT_URL("");
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
session.clear();
session.close();
}
return networkDetails;
}
}