Transaction Aspect not applied for Custom Spring Controller

N

Nettar

Hi,

I am using Google Web Toolkit -> Spring -> Hibernate combination.

I have implemented spring's Controller as below:


public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception
{
service(request, response);
return null;
}

and here is my spring config xml:


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/TESTDB" />
<property name="username" value="root" />
<property name="password" value="pass" />
</bean>

<!-- Hibernate SessionFactory Configuration -->

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>Login.hbm.xml</value>
<!-- Add more Mapping Resources here -->
</list>
</property>
</bean>

<!-- Transaction Management -->

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

<tx:advice id="transactionAdvice"
transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"
rollback-for="java.lang.Exception" />
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="allServiceOperations"
expression="execution(* com.mycompany.service.*Service.*(..))" />
<aop:advisor pointcut-ref="allServiceOperations"
advice-ref="transactionAdvice" />
</aop:config>

This is my service class:


package com.mycompany.service;

import com.mycompany.spring.GWTSpringController;
import com.mycompany.service.LoginService;
import com.mycompany.databeans.Login;
import com.mycompany.controller.LoginController;

public class LoginServiceImpl extends GWTSpringController implements
LoginService
{
private LoginController loginController;

public void setLoginController(LoginController loginController)
{
this.loginController = loginController;
}

public boolean login(Login login)
{
return loginController.login(login);
}
}


Now, when I make a request, I get an exception which says:


org.hibernate.HibernateException: No Hibernate Session bound to thread,
and configuration does not allow creation of non-transactional one here



However, I change the pointcut expression to

execution(* com.mycompany.controller.*Controller.*(..))

it works fine.

Why am I facing this problem?

Is something wrong going on when the Google Web Toolkit invokes login()
on my service implementation because of which Spring cannot apply
transaction aspect?

Kindly help me.

Regards,
Jayarama Nettar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top