Basic settings are all fine now and I started to try transactions. Struts+Spring+Hibernate annotation transaction manager. This is the sample code in Action, will call a service class:
userService.addUser();
Here is the addUser()
method in service class:
@Transactional(value="deu" )
public void addUser() {
userDao.addUser();
this.addUser2();
}
First, I called addUser
in userDao, which will insert a user. Second, I called addUser2
in another method in this service class.
@Transactional(value="deu" , propagation=Propagation.REQUIRES_NEW )
public void addUser2() {
//should be a new transaction and will not affect the previous one.
//this one will fail but should not affect the previous one.
userDao.addUserFail();
}
And this one will failed due to null PK. I suppose the second call (addUser2
) will fail but will not affect the previous one. However, the user is not inserted.
If I only call:
@Transactional(value="deu" )
public void addUser() {
userDao.addUser();
//this.addUser2();
}
It is working, meaning basic settings like database is not wrong.
Any idea?