Understanding Spring transactions - What happens when a transactional method calls another transactional method?
By : user2452748
Date : March 29 2020, 07:55 AM
wish helps you Two answers: a) don't do it. Use @Transactional in the service layer or the dao layer, but not both (the service layer is the usual choice, as you probably want one transaction per service method) code :
proxy bean
a() --> a()
|
V
b() --> b()
proxy bean
service a() --> a()
|
/---------/
|
V
dao b() --> b()
|
Making Spring 3 MVC controller method Transactional
By : Long Doan
Date : March 29 2020, 07:55 AM
Any of those help You'll need to implement an interface so that Spring has something it can use as a Proxy interface: code :
@Controller
public interface AuthenticationController {
ModelAndView home(HttpServletRequest request, HttpServletResponse response);
}
@Controller
public class AuthenticationControllerImpl implements AuthenticationController {
@RequestMapping(value="/home.html",method=RequestMethod.GET)
@Transactional
@Override
ModelAndView home(HttpServletRequest request, HttpServletResponse response){
.....
}
}
|
Transactional method in Scala Play with Slick (similar to Spring @Transactional, maybe?)
By : Paul Graham
Date : March 29 2020, 07:55 AM
help you fix your problem There is no such thing as transactional annotations or the like in slick. Your second "do not want" is actually the way to go. It's totally reasonable to return DBIO[User] from your DAO which does not defeat their purpose at all. It's the way slick works. code :
class UserController @Inject(userService: UserService) {
def register(userData: UserData) = {
userService.save(userData).map(result => Ok(result))
}
}
class UserService @Inject(userDao: UserDao, addressDao: AddressDao) {
def save(userData: UserData): Future[User] = {
val action = (for {
savedUser <- userDao.save(userData.toUser)
savedAddress <- addressDao.save(userData.addressData.toAddress)
whatever <- DBIO.successful(nonDbStuff)
} yield (savedUser, savedAddress)).transactionally
db.run(action).map(result => result._1.copy(result._2))
}
}
class SlickUserDao {
def save(user: User): DBIO[User] = {
(UserSchema.users returning UserSchema.users).insertOrUpdate(user)
}
}
|
Spring transactional method gets rollback even if exception is catched in non-transactional method or in controller
By : Octavio
Date : March 29 2020, 07:55 AM
Any of those help Does this mean that the proxy that spring uses already rolled back the transaction even before i catch the exception?
|
Spring Boot With @Transactional annotated method, calls other transactional methods and throws an Exception
By : user3524703
Date : March 29 2020, 07:55 AM
I hope this helps . Make sure that the method annotated with @Transactional is declared as public and called by a different class. A transactional method must be public so that Spring can override it and it must be called from outside the defining class so that the invocation can go through a proxy.
|