Transaction Aspect not applied for Custom Spring Controller

Discussion in 'Java' started by Nettar, Dec 1, 2006.

  1. Nettar

    Nettar Guest

    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.
     
    Nettar, Dec 1, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rmn190
    Replies:
    2
    Views:
    2,476
    Arne Vajhøj
    Jan 10, 2008
  2. Goldfish
    Replies:
    1
    Views:
    836
    Goldfish
    Nov 6, 2008
  3. Michael Earls
    Replies:
    3
    Views:
    3,401
    MBUnit
    Mar 24, 2009
  4. albert kao
    Replies:
    1
    Views:
    2,082
    marisa lee
    Apr 10, 2010
  5. Vencz Istv?n
    Replies:
    2
    Views:
    310
Loading...

Share This Page