@Transaction annotation between layers in Spring -
what difference in using @transactional
annotation in domain/service layer , dao layer. provide advantage using in domain layer.
it practice use @transactional
in service layer because governs logic needed identify scope of database and/or business transaction. persistence layer design doesn't know scope of transaction.
daos can made @transactional
other bean, it's common practice use in service layer. tend because want separation of concerns. persistence layer retrieve / stores data , forth database.
for example, if want transfer amount 1 account another, need 2 operations, 1 account needs debited other needs credited. so, scope of these operation known service layer , not persistence layer.
the persistence layer cannot know transaction it's in, take example method person.updateusername()
. should run in it's own separate transaction always? there no way know, depends on business logic calling it.
here few thread should read
Comments
Post a Comment