In ActiveRecord its possible to check if the state of an object is valid at a certain point in time.
>> foo.valid?
=> false
Is there a way to do something similar in JPA2, since the validation framework actually gets triggered in JPA prior to save | update
Yes, you can create event listeners that are triggered when different events occur, such before the entity is persisted , modified, etc.
Here’s a basic usage
You can also create callback-logic in separate classes and attach those listeners to entity beans via class level annotations (@EntityListeners).
There’s a lot of stuff here about the order in which these listeners are called, inheriting them, etc to detail it here. Look it up.