0

我创建了一个自定义约束,只希望在持久化前调用它。另外,我已经创建了验证组,并根据规范将其设置在 persistence.xml 文件中。似乎在正确的时间(预持久)调用了验证,通过我的自定义约束实现等等,但是当验证完成时我得到了下面的异常。

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>
4

0 回答 0