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:
- do need put under @transactional method?
- if not necessary , still so, there performance cost?
- 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
Post a Comment