java - Does it worth to put entity under @Transactional service layer if just for searching? -


in spring mvc, put jpa entity (from domain layer) manipulation under service layer , crud actions, have make service method or class @transactional.

but, thinking, if regular finder method, like

myentity myentity = myentity.findbyaliceandbob(alice alice, bob bob); 

so questions are:

  1. do need put under @transactional method?
  2. if not necessary , still so, there performance cost?
  3. if not necessary, why not call finder method controller?

simple answers:

do need put under @transactional method?

no.

if not necessary , still so, there performance cost?

yes, you're opening transaction , closing when don't need (note impact on database depends on rdbms vendor).

if not necessary, why not call finder method controller?

you can it, imo shouldn't since break layered structure. operations against data source (in case, database) must done in dao layer, not in service layer.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -