カスタム制約を作成しましたが、永続化前の時点でのみ呼び出されるようにしたいと考えています。また、検証グループを作成し、仕様に従ってpersistence.xmlファイルに設定しました。検証が適切なタイミングで呼び出され (pre-persist)、カスタム制約の実装を通過しているようですが、検証が完了すると以下の例外が発生します。
Caused by: javax.validation.ConstraintViolationException: validation failed for classes [br.com.rcetecnologia.model.Orcamento] during persist time for groups [br.com.rcetecnologia.validator.annotations.ValidateOnPersistOnly, ]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:155)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:94)
at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:178)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795)
at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.flush(FullTextEntityManagerImpl.java:157)
私のpersistence.xmlファイル:
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
...
<validation-mode>CALLBACK</validation-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.search.default.directory_provider" value="filesystem"/>
<property name="hibernate.search.default.indexBase" value="/Users/gyowannyqueiroz/temp/indexes"/>
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="javax.persistence.validation.group.pre-persist" value="br.com.rcetecnologia.validator.annotations.ValidateOnPersistOnly" />
</properties>
</persistence-unit>