This content has been marked as final. Show 2 replies
Can you set it in persistence.xml instead?
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:
(Sorry for the font. The formatting options are difficult to use.)