Hi,
if you want to control validation yourself it might be better to manually control the validation by using the
Validator directly. I am not sure why exactly the behavior is as described, but it is in accordance w/ the spec. Here are some quotes from the persistence spec:
Quote:
This specification supports the use of bean validation for the automatic validation of entities upon the
pre-persist, pre-update, and pre-remove lifecycle validation events.
Quote:
The PreUpdate and PostUpdate callbacks occur before and after the database update operations to
entity data respectively. These database operations may occur at the time the entity state is updated or
they may occur at the time state is flushed to the database (which may be at the end of the transaction).
Note that it is implementation-dependent as to whether PreUpdate and PostUpdate callbacks
occur when an entity is persisted and subsequently modified in a single transaction or
when an entity is modified and subsequently removed within a single transaction. Portable
applications should not rely on such behavior.
You can turn off automatic validation via setting
javax.persistence.validation.mode to
none. Or you can define which validation group should be targeted via the events using
javax.persistence.validation.group.pre-[persist|update|remove]. Not sure whether this helps you, since it sill does not give any guarantee when the event is triggered.
--Hardy