Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring-Hibernate One to many relationship persistence
    primarykey
    data
    text
    <p>we have Three tables People(id, name), Registrations(id, p_id, sub_id,sem, date), Subjects(id,name, instructor)... I want to know what is the correct layer to write logic to persist list of Registration objects to the db? I mean currently I have following code in ResitrationController class..</p> <pre><code>@RequestMapping(..) public String addRegistrations(@RequestParam(value="personId", required=true) int personId, @RequestParam(value="subjectIdList", required=true) List&lt;Integer&gt; subjectIdList){ List&lt;Registrations&gt; registrationList = new ArrayList&lt;Registrations&gt;(); for(int subjectId : subjectIdList){ Registration registration = new Registration(); registration.setSem("fall-11"); registration.setDate(new Date()); registration.setPerson(personService.getPersonById(personId)); registration.setSubject(subjectService.getSubjectById(subjectId)); registrationList.add(registration); } registrationService.addRegistrations(registrationList); } </code></pre> <p>RegistrationService's addRegistration method just calls the same method on RegistrationDao RegistraionService(){ @Autowired REgistraionDao regDao;</p> <pre><code> @Transactional addRegistration(registrationList){ regDao.addRegistration(registrationList); } } RegistrationDao(){ @Autowired SessionFactory sessionFactory; addRegistration(registrationList){ for(Registration registration: registrationList){ sessionFactory.getCurrentSession().save(registration); } } } </code></pre> <p>I want to know if it is a correct way to have this logic in the controller method or to be shifted to some other place? I really want to send a list of registrations to the RegistrationService method because I would like the entire transaction to roll back even if one of the objects is not persisted.. thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload