Spring ORM 4.0.5 and Hibernate 4.3.5 - Unable to save database

I am using Spring ORM 4.0.5 and Hibernate 4.3.5 and I am having difficulty

When I try to call the dao method from tomcat, I get the following error

    20140527 12:25:00,031 IST DEBUG hibernate4.HibernateTemplate [Check App Scheduler_Worker-1] Could not retrieve pre-bound Hibernate session
org.hibernate.HibernateException: No Session found for current thread
    at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
    at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:325)

I call my dao methods through the service layer from my actions. When I run the dao test from junit using the same Spring xml file, it works fine.

Here is the contents of my Spring configuration file - the data sources are configured and loaded separately.

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd  
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- Hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="appDataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>

        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>config/hibernateMappings/User.hbm.xml</value>
        </list>
    </property>

</bean>

      

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <!-- the transactional semantics... -->
    <tx:attributes>
        <!-- all methods starting with get are read-only -->
        <tx:method name="get*" read-only="true"/>
        <!-- other methods use the default transaction settings (see below) -->
        <tx:method name="" read-only="false"/>
    </tx:attributes>
</tx:advice>

 <aop:config>
     <aop:pointcut id="servicesOperation" expression="execution(* com.app.services.user..*(..))"/>       
    <aop:advisor advice-ref="txAdvice" pointcut-ref="servicesOperation"/>
</aop:config>

Any help on this is greatly appreciated.

+2
source share
1 answer

The error was pointed out by M. Dane

I have configured the following for me

<tx:method name="" read-only="false"/>

Changing it to the following, everything works correctly

<tx:method name="*" read-only="false"/>
0

All Articles