I upgrading hibernate3 to hibernate4 also i did all the changes but i am getting 'Could not retrieve pre-bound Hibernate session' exceptions in logs -
2016-01-28 12:27:46.433 3a37210f d 00000000000000000000000000000000 002e:could not retrieve pre-bound hibernate session "org.hibernate.hibernateexception: no session found current thread @ org.springframework.orm.hibernate4.springsessioncontext.currentsession(springsessioncontext.java:106) @ org.hibernate.internal.sessionfactoryimpl.getcurrentsession(sessionfactoryimpl.java:1014) @ org.springframework.orm.hibernate4.hibernatetemplate.doexecute(hibernatetemplate.java:325) @ org.springframework.orm.hibernate4.hibernatetemplate.execute(hibernatetemplate.java:295) @ com.fusionone.pml.dao.hibernate.abstractdao.executecallback(abstractdao.java:398) @ com.fusionone.pml.dao.hibernate.abstractdao.listinner(abstractdao.java:300) @ com.fusionone.pml.dao.hibernate.abstractdao.list(abstractdao.java:262) @ com.fusionone.pml.dao.hibernate.extsharedaoimpl.listexpiredshares(extsharedaoimpl.java:63) @ com.fusionone.nab.apps.service.impl.extshareserviceimpl.listexpiredshares(extshareserviceimpl.java:628) @ com.fusionone.wsg.nab.scheduler.extshareexpiredscheduler.cleanup(extshareexpiredscheduler.java:111) @ com.fusionone.wsg.nab.scheduler.extshareexpiredscheduler.execute(extshareexpiredscheduler.java:99) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ org.springframework.util.methodinvoker.invoke(methodinvoker.java:269) @ org.springframework.scheduling.quartz.methodinvokingjobdetailfactorybean$methodinvokingjob.executeinternal(methodinvokingjobdetailfactorybean.java:321) @ org.springframework.scheduling.quartz.quartzjobbean.execute(quartzjobbean.java:111) @ org.quartz.core.jobrunshell.run(jobrunshell.java:202) @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:525) " 2016-01-28 12:27:46.441 3a37210f d 00000000000000000000000000000000 000b:f1exception "8 sql error (named query not known: extshare.find_all_shares_expired; nested exception org.hibernate.mappingexception: named query not known: extshare.find_all_shares_expired) @ com.fusionone.pml.dao.hibernate.abstractdao.executecallback(abstractdao.java:400) @ com.fusionone.pml.dao.hibernate.abstractdao.listinner(abstractdao.java:300) @ com.fusionone.pml.dao.hibernate.abstractdao.list(abstractdao.java:262) @ com.fusionone.pml.dao.hibernate.extsharedaoimpl.listexpiredshares(extsharedaoimpl.java:63) @ com.fusionone.nab.apps.service.impl.extshareserviceimpl.listexpiredshares(extshareserviceimpl.java:628) @ com.fusionone.wsg.nab.scheduler.extshareexpiredscheduler.cleanup(extshareexpiredscheduler.java:111) @ com.fusionone.wsg.nab.scheduler.
i upgrading hibernate4.3.11 using spring.4.0 in project.
i loading session factory , mapping resources extending localsessionfactorybean method buildsessionfactorymethod.
@override protected sessionfactory buildsessionfactory(localsessionfactorybuilder localsessionfactorybuilder){ sessionfactory sessionfactory = null; pmldialectmappings dialectmappings = null; string[] mappingresources = null; try { configuration configuration = new configuration(); // building mappinglocations configuration configuration = new configuration(); // building mappinglocations dialectmappings = dialectmappingslocator.locatedialectmappings(configuration); if (dialectmappings != null) { setmappingresources(dialectmappings.getallmappingresources()); abstractdao.setdialectsettings(dialectmappings); } serviceregistry builder = new standardserviceregistrybuilder().applysettings(configuration.getproperties()).build(); sessionfactory = configuration.buildsessionfactory(builder); string schema = configuration.getproperty("hibernate.default_schema"); return super.buildsessionfactory(localsessionfactorybuilder); }
is above code correct create sessionfactory? saw above way create session factory , loading mappingresources in same method. correct or not? in hibernate3 loading mapping resources in getconfiguration method. deprecated in hibernate4 thought load mappingresources in buildsessionfactory method only.
also in google got if add below property 'no hibernate session' error go didn't worked me. please give other suggestions.
hibernate.current_session_context_class=org.springframework.orm.hibernate4.springsessioncontext
code in hibernate 3 build sessionfactory , load mappingresource
@override protected sessionfactory newsessionfactory(configuration config) { try { string schema = config.getproperty("hibernate.default_schema"); if (schema != null && schema.length() > 0) { abstractdao.setschemaname(schema); } else { logger.get(constants.pml_logger).warning( "property 'hibernate.default_schema' not set: using default"); } } catch (throwable t) { logger.get(constants.pml_logger).exception(logtype.critical, null, null, "pmlsessionfactorybean: newsessionfactory method failed", t); throw new hibernateexception(t.getmessage()); } return super.newsessionfactory(config); } /** * @return configuration * @see org.springframework.orm.hibernate3.localsessionfactorybean#newconfiguration() */ @override protected configuration newconfiguration() { configuration configuration = super.newconfiguration(); // building mappinglocations pmldialectmappings dialectmappings = dialectmappingslocator.locatedialectmappings(configuration); if (dialectmappings != null) { setmappingresources(dialectmappings.getallmappingresources()); abstractdao.setdialectsettings(dialectmappings); } return configuration; } } application-context.xml ********************* <bean id="pmljdbcproperties" class="com.fusionone.core.util.filteredproperties"> <property name="location" value="classpath:jdbc.properties" /> <constructor-arg value="pml" /> </bean> <bean id="pmldatasource" class="com.fusionone.core.db.pool.monitoreddatasourcefactory" destroy-method="close" factory-method="createdatasource"> <constructor-arg ref="pmljdbcproperties" /> </bean> <bean id="pmldefaultdialectsettings" class="com.fusionone.pml.bean.pmldialectmappings" lazy-init="true" autowire-candidate="false"> <property name="mappingresources"> <list> <value>hibernate-mappings/brewapp.hbm.xml</value> <value>hibernate-mappings/contact.hbm.xml</value> <value>hibernate-mappings/deletedcontact.hbm.xml</value> <value>hibernate-mappings/deletedcontactgroup.hbm.xml</value> </list> </property> <property name="daointerfaceimpls"> <map> <entry key="deletedcontactdao" value="com.fusionone.pml.dao.hibernate.deletedcontactdaoimpl" /> <entry key="deletedcontactgroupdao" value="com.fusionone.pml.dao.hibernate.deletedcontactgroupdaoimpl" /> </map> </property> <bean id="dialectmappingslocator" class="com.fusionone.pml.bean.dialectmappingslocator" autowire="bytype"> </bean> <bean id="pmlsessionfactory" class="com.fusionone.pml.bean.pmlsessionfactorybean"> <property name="datasource"> <ref bean="pmldatasource" /> </property> <property name="dialectmappingslocator" ref="dialectmappingslocator" /> <property name="hibernateproperties"> <props> <prop key="hibernate.jdbc.use_get_generated_keys"> false </prop> <prop key="hibernate.cache.provider_class"> net.sf.ehcache.hibernate.ehcacheprovider </prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.jdbc.batch_size">150</prop> </props> </property> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory"> <ref bean="pmlsessionfactory" /> </property> <property name="nestedtransactionallowed" value="true" /> </bean>
hibernate 4 changed cache regionfactory , change transanctionmanager hibernate 4.
i change above application context xml as
<bean id="pmljdbcproperties" class="com.fusionone.core.util.filteredproperties"> <property name="location" value="classpath:jdbc.properties" /> <constructor-arg value="pml" /> </bean> <bean id="pmldatasource" class="com.fusionone.core.db.pool.monitoreddatasourcefactory" destroy-method="close" factory-method="createdatasource"> <constructor-arg ref="pmljdbcproperties" /> </bean> <bean id="pmldefaultdialectsettings" class="com.fusionone.pml.bean.pmldialectmappings" lazy-init="true" autowire-candidate="false"> <property name="mappingresources"> <list> <value>hibernate-mappings/brewapp.hbm.xml</value> <value>hibernate-mappings/contact.hbm.xml</value> <value>hibernate-mappings/deletedcontact.hbm.xml</value> <value>hibernate-mappings/deletedcontactgroup.hbm.xml</value> </list> </property> <property name="daointerfaceimpls"> <map> <entry key="deletedcontactdao" value="com.fusionone.pml.dao.hibernate.deletedcontactdaoimpl" /> <entry key="deletedcontactgroupdao" value="com.fusionone.pml.dao.hibernate.deletedcontactgroupdaoimpl" /> </map> </property> <bean id="dialectmappingslocator" class="com.fusionone.pml.bean.dialectmappingslocator" autowire="bytype"> </bean> <bean id="pmlsessionfactory" class="com.fusionone.pml.bean.pmlsessionfactorybean"> <property name="datasource"> <ref bean="pmldatasource" /> </property> <property name="dialectmappingslocator" ref="dialectmappingslocator" /> <property name="hibernateproperties"> <props> <prop key="hibernate.jdbc.use_get_generated_keys"> false </prop> <prop key="hibernate.cache.region.provider_class"> org.hibernate.cache.ehcache.ehcacheregionfactory </prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.jdbc.batch_size">150</prop> </props> </property> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory"> <ref bean="pmlsessionfactory" /> </property> <property name="nestedtransactionallowed" value="true" /> </bean>
mainly need how create sessionfactory , how load mappingresources.
changed localsessionfactorybean
code below. mapping resources loaded properly. previous in hibernate 3 configuration loading mappings before sessionfactorybean
loads. in hiberate4 not that, have add resources manually localsessionfactory
bean. same thing added it's worked. thought setmappingresources
enough load need addresource
localsessionfactory
bean also.
dialectmappings = dialectmappingslocator.locatedialectmappings(configuration); if (dialectmappings != null) { setmappingresources(dialectmappings.getallmappingresources()); abstractdao.setdialectsettings(dialectmappings); } for(string resource : dialectmappings.getparentdialectmappings().getallmappingresources()) { configuration.addresource(resource); }
after implemented proper nullsafeget
, nullsafeset
implemementaion, our project upgraded hibernate 4.3.11. able add query hints queries helps force indexing tables. stackoverflow help.
Comments
Post a Comment