@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

where @transactional annotation belong?

where should "@transactional" place service layer or dao


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -