Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:51:30+00:00 2026-05-15T07:51:30+00:00

I am struggling to get my spring managed transactions to commit, could someone please

  • 0

I am struggling to get my spring managed transactions to commit, could someone please spot what I have done wrong. All my tables are mysql InnonDB tables. My RemoteServiceServlet (GWT) is as follows:

public class TrainTrackServiceImpl extends RemoteServiceServlet implements TrainTrackService {

 @Autowired
 private DAO dao;

 @Override
 public void init(ServletConfig config) throws ServletException {
  super.init(config);
  WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
  AutowireCapableBeanFactory beanFactory = ctx.getAutowireCapableBeanFactory();
  beanFactory.autowireBean(this);
 }

    @Transactional(propagation= Propagation.REQUIRED, rollbackFor=Exception.class)
 public UserDTO createUser(String firstName, String lastName,
   String idNumber, String cellPhone, String email, int merchantId) {
  User user = new User();

  user.setFirstName(firstName);
  user.setLastName(lastName);
  user.setIdNumber(idNumber);
  user.setCellphone(cellPhone);
  user.setEmail(email);
        user.setDateCreated(new Date());

  Merchant merchant = (Merchant) dao.find(Merchant.class, merchantId);
  if (merchant != null) {
   user.setMerchant(merchant);
  }

  // Save the user.
  dao.saveOrUpdate(user);
  UserDTO dto = new UserDTO();
  dto.id = user.getId();
  dto.firstName = user.getFirstName();
  dto.lastName = user.getLastName();
  return dto;
 }

The DAO is as follows:

public class DAO extends HibernateDaoSupport {

private String adminUsername;
private String adminPassword;
private String godUsername;
private String godPassword;

public String getAdminUsername() {
    return adminUsername;
}

public void setAdminUsername(String adminUsername) {
    this.adminUsername = adminUsername;
}

public String getAdminPassword() {
    return adminPassword;
}

public void setAdminPassword(String adminPassword) {
    this.adminPassword = adminPassword;
}

public String getGodUsername() {
    return godUsername;
}

public void setGodUsername(String godUsername) {
    this.godUsername = godUsername;
}

public String getGodPassword() {
    return godPassword;
}

public void setGodPassword(String godPassword) {
    this.godPassword = godPassword;
}

public void saveOrUpdate(ModelObject obj) {
    getHibernateTemplate().saveOrUpdate(obj);
}

And my applicationContext.xml is as follows:

<context:annotation-config/>

<context:component-scan base-package="za.co.xxx.traintrack.server"/>

<!-- Application properties -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>file:${user.dir}/@propertiesFile@</value>
        </list>
    </property>
</bean>

<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${connection.dialect}</prop>
            <prop key="hibernate.connection.username">${connection.username}</prop>
            <prop key="hibernate.connection.password">${connection.password}</prop>
            <prop key="hibernate.connection.url">${connection.url}</prop>
            <prop key="hibernate.connection.driver_class">${connection.driver.class}</prop>
            <prop key="hibernate.show_sql">${show.sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">20</prop>
            <prop key="hibernate.c3p0.timeout">300</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
            <prop key="hibernate.c3p0.idle_test_period">60</prop>
        </props>
    </property>
    <property name="annotatedClasses">
        <list>
            <value>za.co.xxx.traintrack.server.model.Answer</value>
            <value>za.co.xxx.traintrack.server.model.Company</value>
            <value>za.co.xxx.traintrack.server.model.CompanyRegion</value>
            <value>za.co.xxx.traintrack.server.model.Merchant</value>
            <value>za.co.xxx.traintrack.server.model.Module</value>
            <value>za.co.xxx.traintrack.server.model.Question</value>
            <value>za.co.xxx.traintrack.server.model.User</value>
            <value>za.co.xxx.traintrack.server.model.CompletedModule</value>
        </list>
    </property>
</bean>

<bean id="dao" class="za.co.xxx.traintrack.server.DAO">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="adminUsername" value="${admin.user.name}"/>
    <property name="adminPassword" value="${admin.user.password}"/>
    <property name="godUsername" value="${god.user.name}"/>
    <property name="godPassword" value="${god.user.password}"/>
</bean>

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

<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>

If I change the sessionFactory property to be autoCommit=true then my object does get persisited.

<prop key="hibernate.connection.autocommit">true</prop>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:51:30+00:00Added an answer on May 15, 2026 at 7:51 am

    When GWT calls createUser, this call doesn’t go through a Spring’s transactional proxy. In order to use @Transactional you can introduce additional level of indirection:

    public class TrainTrackServiceWrapper extends RemoteServiceServlet implements TrainTrackService { 
    
        @Autowired 
        private TrainTrackServiceImpl impl; 
    
        ...
    
        public UserDTO createUser(String firstName, String lastName, 
            String idNumber, String cellPhone, String email, int merchantId) { 
    
            return impl.createUser(firstName, lastName, idNumber, cellPhone, email, merchantId);
        }
    
    }
    
    public class TrainTrackServiceImpl implements TrainTrackService { 
    
        @Autowired 
        private DAO dao; 
    
        @Transactional(propagation= Propagation.REQUIRED, rollbackFor=Exception.class) 
        public UserDTO createUser(String firstName, String lastName, 
           String idNumber, String cellPhone, String email, int merchantId) { 
            ...
        }
    }
    

    EDIT: You may also use spring4gwt instead of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.