How to handle transactions with Spring Data JPA? -


i start creating new application , wanted feedback on approach plan on using. using spring , spring data jpa.

  1. can controllers call domain services , repositories or should controller make calls application , infrastructure services?

  2. if "ok" call domain services , repositories controller , domain service operation needs transaction, can/should put @transactional annotation on domain service method? or should have application service wraps call (not sure approach because end bunch of pass through methods)?

  3. if not "ok" call domain services , repositories controller need create application services wrap possible domain service calls(like said in 2 lot of pass through methods)?

the best solution can come following:

  1. repositories have @transactional annotation propagation required when writing database , propagation set readonly=true , propagation set supports when reading database.

  2. application , domain services add @transactional annotation needed

if controller ever needs make make direct call repository domain service or application service can. no pass throughs.

enter image description here

i not clear question. domain services doing? knew application services , domain repositories well.

in spring , there 2 layers service , data access layer. service layer can used @service (in design application services) not used @transactional tag.

data access layer used @repository tag , @transactional tag, because layer directly connected , make operation database. so, know 's function of domain service. not clear that.

thanks buddy.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -