Hellu,
I just changed my application such that i uses hibernate 3.0 and Springframework 1.2.5.
I only get the exeption that my hibernate session isn't bound to a thread when I use it in the following way:
I have a Service layer that talk to DAO's.
In the DAO, I have:
Just like explained in the new Springframework manual, and in the method:Code:private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; }
before using the session to look up something in the db. This is how I understood it from the manual.Code:this.sessionFactory.getCurrentSession();
When I call this method above, I get this hiberate exception, telling me that no session is bound.
Just before I get the exception i get the following logging:
I then noticed, though some debubbing, that I do have a NEW session, but that the following method (in SessionFactoryUtils) returns false:Code:DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Opening Hibernate Session DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
This method will look if I have a current session bound to my thread.Code:isSessionTransactional(session, sessionFactory)
So that means that I do have a NEW session but no current session and so notransaction. Is this correct? and Why not ?
Below you find the important parts from the beans.xml file.
Please some help.
I noticed that the getCurrentSession() method is not allowed to create a new session and it looks up the session bound to the current transaction. So basically the current transaction must first already have created a session. But where and how??...do I make sure this happens..??... I would suppose throught the correct transaction configuration in the beans.xml below... but appearantly... it's enough... or it contains a mistake...
Cheers,
Ed Bras
Code:<!-- The hibernate session factory --> <bean id="HibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value>MrMain.hbm.xml</value> <value>MrMainProperty.hbm.xml</value> <value>MrProperty.hbm.xml</value> <value>MrPropertyKey.hbm.xml</value> <value>MrRelated.hbm.xml</value> <value>MrRelatedProperty.hbm.xml</value> <value>MrDbQueries.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.connection.pool_size"> 3 </prop> <prop key="hibernate.show_sql"> true </prop> <prop key="hibernate.connection.isolation"> 2 </prop> </props> </property> <property name="dataSource"> <ref bean="DataSource"/> </property> </bean> <!-- The main dao implementation that does the real work --> <bean id="MainDao" class="org.ited.mr.persist.dao.impl.BasicMainDao"> <property name="sessionFactory"> <ref local="HibernateSessionFactory"/> </property> <property name="mainCls"> <ref bean="MrMain"/> </property> <property name="persistUtility"> <ref bean="PersistUtility"/> </property> </bean> <!-- The backend service --> <bean id="Service" class="org.ited.mr.service.impl.BasicService"> <property name="mainDao"> <ref bean="MainDao"/> </property> <property name="relatedDao"> <ref bean="RelatedDao"/> </property> <property name="dtoConverter"> <ref bean="DtoConverter"/> </property> <property name="ctxUtils"> <ref bean="ContextUtility"/> </property> <property name="mainCls"> <ref bean="Main"/> </property> <property name="relatedCls"> <ref bean="Related"/> </property> </bean> <!-- Transaction demarcation of the backend service --> <bean id="BackendServiceProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="TransactionManager"/> </property> <property name="target"> <ref bean="Service"/> </property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean>


Reply With Quote