Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring transactions not committing
    primarykey
    data
    text
    <p>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:</p> <pre><code>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; } </code></pre> <p>The DAO is as follows:</p> <pre><code>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); } </code></pre> <p>And my applicationContext.xml is as follows:</p> <pre><code>&lt;context:annotation-config/&gt; &lt;context:component-scan base-package="za.co.xxx.traintrack.server"/&gt; &lt;!-- Application properties --&gt; &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="locations"&gt; &lt;list&gt; &lt;value&gt;file:${user.dir}/@propertiesFile@&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt;${connection.dialect}&lt;/prop&gt; &lt;prop key="hibernate.connection.username"&gt;${connection.username}&lt;/prop&gt; &lt;prop key="hibernate.connection.password"&gt;${connection.password}&lt;/prop&gt; &lt;prop key="hibernate.connection.url"&gt;${connection.url}&lt;/prop&gt; &lt;prop key="hibernate.connection.driver_class"&gt;${connection.driver.class}&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;${show.sql}&lt;/prop&gt; &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt; &lt;prop key="hibernate.c3p0.min_size"&gt;5&lt;/prop&gt; &lt;prop key="hibernate.c3p0.max_size"&gt;20&lt;/prop&gt; &lt;prop key="hibernate.c3p0.timeout"&gt;300&lt;/prop&gt; &lt;prop key="hibernate.c3p0.max_statements"&gt;50&lt;/prop&gt; &lt;prop key="hibernate.c3p0.idle_test_period"&gt;60&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.Answer&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.Company&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.CompanyRegion&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.Merchant&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.Module&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.Question&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.User&lt;/value&gt; &lt;value&gt;za.co.xxx.traintrack.server.model.CompletedModule&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="dao" class="za.co.xxx.traintrack.server.DAO"&gt; &lt;property name="sessionFactory" ref="sessionFactory"/&gt; &lt;property name="adminUsername" value="${admin.user.name}"/&gt; &lt;property name="adminPassword" value="${admin.user.password}"/&gt; &lt;property name="godUsername" value="${god.user.name}"/&gt; &lt;property name="godPassword" value="${god.user.password}"/&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory"&gt; &lt;ref local="sessionFactory"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- enable the configuration of transactional behavior based on annotations --&gt; &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; </code></pre> <p></p> <p>If I change the sessionFactory property to be autoCommit=true then my object does get persisited.</p> <pre><code>&lt;prop key="hibernate.connection.autocommit"&gt;true&lt;/prop&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload