My Spring application is layered as Bean, Service and DAO. All the @Transactional annotations are in service layer.
This is the pseudo code in one particular scenario.
UserBean.java
saveUser() {
userService.manageUser();
}
UserServiceImpl.java
@Transactional
public void manageUser() {
userDAO.createUser();
userDAO.updateParentUser();
}
UserDAOImpl.java
createUser() {
//insert user record in database
}
updateParentUser() {
//update parent user's database record
}
In my save user test case, the update parent user operation can fail in some cases due to primary key violation which is kind of expected.
As the @Transactional annotation is implemented in service class, this violation exception will be notified in bean class only.
What is the option to get this PK violation notification in my service class? [Then I can handle it from there in a different business process.]
If I add a new method in service class and call manageUser() from there the @Transactional annotation will not work properly. This is due to the limitation/property of AOP. Spring expects external call to @Transactional methods.