2017-09-24 32 views
0

@NotNullまたは@NotEmptyをスキップする方法はありますか?JpaRepository.saveを呼び出すときにセッターメソッドが呼び出されなかった(したがってnull値がある)フィールドの検証はありますか? 。更新時に@NotNull検証をスキップ

:これらのフィールドから @NotNull注釈が JpaRepository.save EntityManager.mergeのように振る舞うので、私はこれらのために @NotNull検証がでキックしないことが予想作るの削除

ここでは上げ検証例外の最初の行です

javax.validation.ConstraintViolationException: Validation failed for classes [com.example.demo.model.db.AppUser] during update time for groups [javax.validation.groups.Default, ] 
List of constraint violations:[ 
    ConstraintViolationImpl{interpolatedMessage='may not be empty', propertyPath=loginName, rootBeanClass=class com.example.demo.model.db.AppUser, messageTemplate='{org.hibernate.validator.constraints.NotEmpty.message}'} 
    ConstraintViolationImpl{interpolatedMessage='may not be empty', propertyPath=pwd, rootBeanClass=class com.example.demo.model.db.AppUser, messageTemplate='{org.hibernate.validator.constraints.NotEmpty.message}'} 
    ConstraintViolationImpl{interpolatedMessage='may not be empty', propertyPath=statusCd, rootBeanClass=class com.example.demo.model.db.AppUser, messageTemplate='{org.hibernate.validator.constraints.NotEmpty.message}'} 
] 
    at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:138) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:86) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:244) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:118) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:582) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:456) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:465) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2963) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2339) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final] 
    at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] 
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.11.6.RELEASE.jar:na] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.6.RELEASE.jar:na] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at com.sun.proxy.$Proxy113.save(Unknown Source) ~[na:na] 
    at com.example.demo.repository.RepositoryWrapperImpl.save(RepositoryWrapperImpl.java:124) ~[classes/:na] 
    at com.example.demo.service.AbstractTransactionalService.save(AbstractTransactionalService.java:20) ~[classes/:na] 
    at com.example.demo.service.AbstractTransactionalService$$FastClassBySpringCGLIB$$f1966d61.invoke(<generated>) ~[classes/:na] 
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669) ~[spring-aop-4.3.10.RELEASE.jar:4.3.10.RELEASE] 
    at com.example.demo.service.Pads010020AppUserService$$EnhancerBySpringCGLIB$$f988b3b1.save(<generated>) ~[classes/:na] 
    at com.example.demo.controller.ServiceDispatcherController.handleAllPut(ServiceDispatcherController.java:115) ~[classes/:na] 
+0

代わりにデフォルトテキストを使用することができます –

答えて

-1

@NotNullは、JSR 303 Bean検証アノテーションです。データベースの制約自体とは何の関係もありません。ただし、HibernateはJSR 303のリファレンス実装であるため、これらの制約をインテリジェントに拾い上げ、データベース制約に変換します。 @Column(nullable = false)は、NULLを宣言するJPAの方法です。 Confusion: @NotNull vs @Column(nullable = false)

JPA @Column(nullable = false)アノテーションに加えて、コード内のヌルも確認する必要があります。

関連する問題