唯一约束违规SDN4

时间:2016-10-24 19:44:50

标签: java neo4j spring-data-neo4j-4

我正在使用带有http驱动程序的SDN 4.1.2和neo4j-org 2.0.4 当其中一个节点上违反了一个唯一约束并且我在一个事务中时,我会被TransactionException抛出 在日志中我看到了

  

org.neo4j.ogm.exception.CypherException:执行Cypher时出错   " Neo.ClientError.Schema.ConstraintValidationFailed&#34 ;;码:   Neo.ClientError.Schema.ConstraintValidationFailed;描述:节点   已经存在441标签城市和财产"名称" = [查谟]

但是,如果我尝试捕获TransactionException,我看不到有关约束违规的任何信息。我想在服务响应中返回约束违规信息。

我应该在服务类中明确执行唯一性检查,而不是依赖于db上的唯一约束吗?

服务类

@Transactional
public void createCity(City city) {
    try {
        cityRepository.save(city);
    }
    catch(Exception e) {
        System.out.println("***********************Inside Service *********************************");
        e.printStackTrace();
        throw e;
    }
}

测试课

    public void testCreateDuplicateCity2() {
    try {
        City city = new City();
        city.setName("Jammu");
        city.setZip("345678");
        service.createCity();
    }
    catch(Exception e){
        System.out.println("######################### Inside test ############################");
        e.printStackTrace();
    }
}

踪迹        

 ***********************Inside Service *********************************
org.neo4j.ogm.exception.CypherException: Error executing Cypher "Neo.ClientError.Schema.ConstraintValidationFailed"; Code: Neo.ClientError.Schema.ConstraintValidationFailed; Description: Node 457 already exists with label City and property "name"=[Jammu]
    at org.neo4j.ogm.drivers.http.response.AbstractHttpResponse.initialise(AbstractHttpResponse.java:83)
    at org.neo4j.ogm.drivers.http.response.AbstractHttpResponse.(AbstractHttpResponse.java:74)
    at org.neo4j.ogm.drivers.http.response.RowModelResponse.(RowModelResponse.java:31)
    at org.neo4j.ogm.drivers.http.request.HttpRequest.execute(HttpRequest.java:123)
    at org.neo4j.ogm.session.request.RequestExecutor.executeSave(RequestExecutor.java:120)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:75)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:44)

    ######################### Inside test ############################

org.neo4j.ogm.exception.TransactionException: Failed to execute request: at org.neo4j.ogm.drivers.http.transaction.HttpTransaction.rollback(HttpTransaction.java:49) at org.springframework.data.neo4j.transaction.Neo4jTransactionManager.rollback(Neo4jTransactionManager.java:60) at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:501) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:284) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) at com.platform.entity.demo.service.CityStateService$$EnhancerBySpringCGLIB$$43ef26b7.createDuplicateCity2() at com.platform.entity.demo.repository.test.UniqueIndexTest.testCreateDuplicateCity2(UniqueIndexTest.java:74)

如果我在调用服务的方法中进行异常处理,则约束违规信息将丢失。

0 个答案:

没有答案