|
Re: BeanValidation at preUpdate for unchanged entities? [message #1064717 is a reply to message #1064627] |
Thu, 20 June 2013 12:16   |
Eclipse User |
|
|
|
The state of the transaction is checked in the beforeCompletion callback EclipseLink receives, and if it does not have a status of STATUS_ACTIVE or STATUS_PREPARING, it should just return without issuing SQL. So if SQL is being issued, it seems your rollback is not occurring on the transaction associated to the committing UnitOfWork/EntityManager, or it is getting the wrong status back from the TransactionManager. What code are you using to mark the transaction for rollback?
As for the BeanValidationListener being called for every managed instance regardless of changes - this looks like a bug. The BeanValidationListener is overriding the preUpdate method when it should using the preUpdateWithChanges method that is used for JPA preUpdate events. Please file a bug and vote for it.
Because the BeanValidationListener is hardcoded and added to a protected collection, a workaround is more complex. You might need to create a dummy ValidatorFactory class that just ignores validation and specify it using the "javax.persistence.validation.factory" property, and then add in your own BeanValidationListener subclass that overrides the preUpdateWithChanges to call its parent's preUpdate event, and the preUpdate event just return. The code within org.eclipse.persistence.internal.jpa.deployment.BeanValidationInitializationHelper's bootstrapBeanValidation innerclass method shows what needs to be done, but using your own subclass instead. Something like:
for (ClassDescriptor descriptor : session.getProject().getOrderedDescriptors()) {
if (descriptor.isDescriptorTypeNormal()) {
//add only to entities
descriptor.getEventManager().addInternalListener(yourValidationListener);
}
}
Best Regards,
Chris
|
|
|
|
Powered by
FUDForum. Page generated in 0.03834 seconds