Search code examples
javahibernatepojodata-consistency

How to validate NOT NULLABLE attributes from a POJO vs list of required attributes?


My issue is that I need to persist in my database two kind of status "VALID" and "INVALID" according to data validation, it means, in my database all attributes are NULLABLE but another process will put status "VALID" if all required values are present and "INVALID" when one or more required values are missing.

I am using a relational model(oracle 11g) and Hibernate 3.

So...

Somebody knows a framework or mechanism to validate data consistency (objects/attributes NOT NULL´s) between a given object (POJO) versus a list (or another POJO) of required objects/attributes?. Note that those objects can have simple attributes or can include other objects or list of objects.

Even more, in some cases the validation has a condition, for example, only validate (check if is NULL) one specific attribute only if another attribute has a certain value.

Currently I have one approach using reflection and one database table to store the parameterization for all my required objects/attributes, but I want to know whether exists another better way.

Thanks in advance


Solution

  • Well, I found a good approach to do this with :

    PropertyUtils.getNestedProperty

    and programming all conditions for nullability.