jeudi 3 septembre 2015

Should Spring DAO classes refer only one object of the model?

I am very new of Spring, I will straight to the point. The layers in my application seem to be rather conventional:

- Controller
- DTO
- Service    
- DAO
- Model

Generally speaking, should every implementation of a DAO interface deal with only one object from the model? (sorry I can find only trivial examples which really don't face this point) Likely sometime in one-to-one relationship, bidirectional, say with only one shared primary key. Hibernate doesn't care, apart from mapping, it can't handle POJO references to each other. Say there is this situation i.e.:

Table1: Parent        Table2: Child
------------------    ----------------------
| PARENT_ID (PK) |<---|CHILD_ID (PK and FK)|
------------------    ----------------------

it will require to maintain updated respectively:

parent.setChild(a_child); // private field of Parent.java
child.setParent(a_parent); // private field of Child.java

Where is - looking at the mentioned layers - the right place for implementing this kind of logic? If Hibernate looks after the mapping between model's objects and DB, who should be the one taking care of the coherence between POJO objects of the model?

My headline question wonders if DAOs can deal with several POJOs from the model, DAOs can also keep those POJOs coherence on.

Many thanks Bye

Aucun commentaire:

Enregistrer un commentaire