Announcement Announcement Module
Collapse
No announcement yet.
How to use a stateless hibernate session in Spring DAO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use a stateless hibernate session in Spring DAO

    I am having an application in struts + spring + hibernate. On the data layer, I am trying to use Spring DAO's in order to perform operations on my MY SQL database. I was under the impression that Spring + Hibernate takes care of the Session being stateless. However this does not seem to be the case as the number of connection threads showing on mysql is high. How to implement stateless session using Spring DAO's The operations I perform are using the getHibernateTemplate() method.
    In case that is not possible, is there any other mechanism to have stateless sessions using Spring DAO's. Below is the application context file.

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>${jdbc.driverClassName}</value>
    </property>
    <property name="url">
    <value>${jdbc.url}</value>
    </property>
    <property name="username">
    <value>${jdbc.username}</value>
    </property>
    <property name="password">
    <value>${jdbc.password}</value>
    </property>
    </bean>


    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
    <list>
    <value>hbm/User.hbm.xml</value>
    -------------------------
    ----------------------
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    ${hibernate.dialect}
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>

    </bean>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="dataSource" ref="dataSource" />
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="userDaoTransaction"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="target" ref="userDaoImpl">

    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="store*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="userDaoImpl"
    class="com.mindteck.pep.dl.dao.impl.UserDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
Working...
X