spring - Dao and Service of a complex object -


so have complex object, example:

@entity public class house {  private kitchen kitchen; private livingroom livingroom; private mainbedroom mainbedroom; private toilet toilet; etc...   } 

now each object (kitchen,livingroom etc..) in house class extremely complex non primitive fields , not..

i have following services:

@service public houseservice {   }  @service public kitchenservice{   } 

.. , on..

what question is:

if create new house object within houseservice, have use other services creation method?

it seems don't need other services @ since house root of objects , need 1 (apparently big) houseservice? right?

i.e. :

houseservice.createnewhouse {  house house  = new house(...); kitchen kitchen = new kitchen(...); ...      house.setkitchen(kitchen);   this.dao.save(house);   return house;    }  } 

although could, don't make life complicated. assume have multiple daos each of entity classes. @inject (or @autowired) , use them directly in eachservice` class.

your @service classes should @transactional gain nothing (unless there specific business logic) going through other @service classes.

instead of

@service public class firstservice {     @autowired     private secondservice secondservice;     @autowired     private firstdao firstdao;      @transactional     public void savefirst(first first) {         secondservice.savesecond(first.getsecond());         firstdao.save(first);     } }  @service public class secondservice {     @autowired     private seconddao seconddao ;      @transactional     public void savesecond(second second) {         seconddao .save(second);     } } 

just go dao directly

@service public class firstservice {     @autowired     private seconddao seconddao;     @autowired     private firstdao firstdao;      @transactional     public void savefirst(first first) {         seconddao.save(first.getsecond());         firstdao.save(first);     } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -