Closed GoogleCodeExporter closed 9 years ago
Looks like you are using MySQL. In that case, ensure you are using InnoDB
tables engine, and not MyISAM, since MyISAM does not support transactions.
Original comment by i...@expresspigeon.com
on 28 Oct 2013 at 10:22
Yes you were right. I had failed to notice that. It works when i change over to
innodb.
I am now trying to integrate with spring transaction manager. However unless i
do an explicit commit transaction the inserts are not happening. Spring
transaction manager should have take care of the commit.
public class App {
public static final Logger log = Logger.getLogger(App.class.getName());
public static void main(String[] args) throws Exception {
new App().dbCall();
}
public void dbCall() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-beans.xml");
DataSource dataSource = (DataSource) ctx.getBean("dataSource");
Base.open(dataSource);
Base.connection().setAutoCommit(false);
this.addEmployee("Jhon", "Doe");
Base.close();
}
@Transactional
public void addEmployee(String firstName, String lastName) {
Employee e1 = new Employee();
e1.set(Employee.FIRST_NAME, firstName);
e1.set(Employee.LAST_NAME, lastName);
e1.set(Employee.SALARY, 1);
e1.saveIt();
Employee e2 = new Employee();
e2.set(Employee.FIRST_NAME, firstName);
e2.set(Employee.LAST_NAME, lastName);
e2.set(Employee.SALARY, 2);
e2.saveIt();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config/>
<tx:annotation-driven/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/simple_test" />
<property name="username" value="root" />
<property name="password" value="manager" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
Original comment by arjun.su...@gmail.com
on 30 Oct 2013 at 5:39
I'm rejecting this issue. Going forward, please post questions to Google Groups:
https://groups.google.com/forum/#!forum/activejdbc-group
and file issues on Githug under corresponding repo: https://github.com/javalite
As far as Spring, please, see that ActiveJDBC does not really manage
transactions.
Please see code here:
https://github.com/javalite/activejdbc/blob/master/activejdbc/src/main/java/org/
javalite/activejdbc/DB.java#L570
and here:
http://javalt.org/p/transactions
So, maybe this question needs to be posted to Spring forum?
I personally never use Spring.
tx
Original comment by i...@polevoy.org
on 30 Oct 2013 at 6:19
Original issue reported on code.google.com by
arjun.su...@gmail.com
on 25 Oct 2013 at 11:52