Where to implement entity compliance checking?

I have a project in which the data model and business layer are located in two different modules. Of course, the bussiness module is dependent on the model module. Authentication of an object is implemented through java-validation-api annotations.

I am wondering where I should implement a correspondence check between entities (a business check in which relationships between different types of entities are checked). Currently, I see the following options:

  • Create custom javax.validation.ConstraintValidators and related annotations. The problem is that the validator needs access to business services, i.e. To get related objects, but the model module should not have a dependency on the business module.
  • Implement conformance checking between entities in the persist / merge methods of business services methods (i.e. using interceptors). This would be possible, but the verification of correspondence between entities was separated from the authentication of the object, and I would like to have only one place for verification.

Which option is preferable? Are there any better deals?

Thanks Sebastian

+3
source share
1 answer

From an ideological point of view, approach 1. is better. Bean Validation works at the model level (in Model-View-Controller), and there is nothing wrong with the fact that the model part speaks to the database. So, for example, you can create DAOs that can be used both with the help of a service level and with the help of model validators to avoid code duplication.

-, Bean Validation. , , ConstraintViolationException , , .. , . , , , , , , , .

, DB 1.

+1

All Articles