I have been using the hibernate.validator framework a bit and like what I see so far. I am wondering what people are doing to express stateful validations. As
Martin Fowler writes, "Often when people talk about a context-free validity, they mean it in terms of saving to a database." In this case, I think the validator package was designed for exactly this context but starts to offer usefulness in other contexts.
As an example of thinks I'm not sure I can express in validations yet:
* dirty checking, i.e. updates to certain columns should fail (not just be excluded from the statement)
* updates or inserts are only valid dependant on a sql query.
* although selects are filterable, is it possible to declaratively state that updates are not allowed when given a user?
It looks like the options we have are:
* give enough information to the domain POJO and express it there.
* write your own validation, add it to the event based code and call it manually using the
Application level validator.
* express state using other annotations and use those to determine context (like Seam I guess)
* something else that I'm not aware of yet?
I dont really want my domain level POJO's to be mucking around with EntiyManagers or Sessions. I saw that emmanuel was not against passing in stateful information in theory somewhere on this board (sorry i cant find the post). Is there a way to do dirty field checking inside a validator? Otherwise it would be nice to have an @AssertTrueOnInsert, and @AssertTrueOnUpdate.
Just wondering what other people are doing here...