This content has been marked as final.
Show 2 replies
-
1. Re: Dynamically bypass Hibernate Validation by overriding ValidateEventListener
njrich28 Aug 30, 2010 3:44 PM (in response to kbrender)Can you set it in persistence.xml instead?
-
2. Re: Dynamically bypass Hibernate Validation by overriding ValidateEventListener
kbrender Sep 2, 2010 3:57 PM (in response to kbrender)Yes. I think I have figured it out. First, I deactivate automatic registration of the default validation listener (Hibernate's ValidateEventListener). Second, I register the custom listener as "pre-insert" and "pre-update". In persistence.xml, these changes appear as follow:
<property name="hibernate.validator.autoregister_listeners" value="false" />
<property name="hibernate.ejb.event.pre-insert" value="org.mypackage.CustomValidateEventListener" />
<property name="hibernate.ejb.event.pre-update" value="org.mypackage.CustomValidateEventListener" />
Thanks for the suggestion! Putting the configuration in persistence.xml seems to work for me, although this configuration is not as ideal as something like "<property name="defaultValidateListener" value="..." />". I derived this solution from the Hibernate documentation on event listeners (http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html) and from this blog which discusses the same problem:
http://www.nearinfinity.com/blogs/page/sleberkn?entry=validating_domain_objects_in_hibernate4
(Sorry for the font. The formatting options are difficult to use.)