Mod4j: Modeling for Java using Domain Specific Languages

Validators are not set when a domain object is restored by hibernate

Details

  • Testcase included:
    yes
  • Number of attachments :
    0

Description

MODFORJ-98 could be worked around by implementing setComestible in the extension point and calling the validation from there. However, this doesn't work because of another issue; the validators are not set when Hibernate restores the object from the database, since the protected no-arg constructor doesn't do anyting.
When a new Part is created, first a Part with empty relations is created and persisted in the database. A split second later this Part is retrieved from the database again, setComestible is invoked and the validators are called. Because the list of validators is empty, validation always succeeds.
Makes me wonder if anyone has ever seen validation working when updating an existing domain object?

Issue Links

Activity

Hide
Johan Vogelzang added a comment -

You're right, the default no-arg constuctor does not unlike the constructor with arguments set the needed validators.

What we could do:

  • In the DomainClassImplBase classes add a new method called setValidators(). This method adds all needed validators to the validation instance variable:
    validation.addValidator(new NotNullValidator(Part.class, "quantity"));
    validation.addValidator(new PartCheckMinimumQuantity());
  • Call this method in all constructors including the no-arg constructor. This would replace the current individual adds to the validator in the constructors. After this add a validation.validate();

This could also apply as workaround. Just implement it in your extension points.

Show
Johan Vogelzang added a comment - You're right, the default no-arg constuctor does not unlike the constructor with arguments set the needed validators. What we could do:
  • In the DomainClassImplBase classes add a new method called setValidators(). This method adds all needed validators to the validation instance variable: validation.addValidator(new NotNullValidator(Part.class, "quantity")); validation.addValidator(new PartCheckMinimumQuantity());
  • Call this method in all constructors including the no-arg constructor. This would replace the current individual adds to the validator in the constructors. After this add a validation.validate();
This could also apply as workaround. Just implement it in your extension points.
Hide
Eric Jan Malotaux added a comment -

Fixed in revision 2272 (version 1.0.1) and 2273 (1.1.0-beta-1)

Show
Eric Jan Malotaux added a comment - Fixed in revision 2272 (version 1.0.1) and 2273 (1.1.0-beta-1)

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: