1 Reply Latest reply on Nov 12, 2007 9:57 AM by Pete Muir

    Validator gets called twice

    Chr D Newbie

      Hi,

      I have a question of understanding:

      I have written a validator, which is working pretty fine,... well actually it should.

      The validator gets called twice.

      If I create a new Object of an entity with an autogenerated ID and persist it,
      the validator gets called before this entity has an ID and returns TRUE, so no validation error.

      But then the thing:
      After the entity got his ID it gets validated again and then (caused by some validation rules i have written) the validator returns false and there is no message thrown to the JSF, instead i get a regular "Transaction failed".

      Any ideas why the validator is called twice and how to avoid this?

        • 1. Re: Validator gets called twice
          Pete Muir Master

          The validator is called once by JSF to validate your entity in the PROCESS VALIDATION phase and once by hibernate when inserting data to the database. You need to write your Validator to be consistent and not return different results depending on the state of other fields in the entity.