2

I am using SDN 4.1.2 and neo4j-org 2.0.4 with http driver When an unique constraint is getting violated on one of the nodes and I am within a transaction, I am getting TransactionException being thrown In the logs I see

org.neo4j.ogm.exception.CypherException: Error executing Cypher "Neo.ClientError.Schema.ConstraintValidationFailed"; Code: Neo.ClientError.Schema.ConstraintValidationFailed; Description: Node 441 already exists with label City and property "name"=[Jammu]

But if I try to catch TransactionException, I do not see any information about the constraint violation. I would like to return the constraint violation information in my service response.

Should I explicitly do a uniqueness check in my service class instead of relying on the unique constraint on the db?


Service class

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

Test class

    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();
    }
}

Stacktraces

 ***********************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)

If I have my exception handling in the method calling the service, then the constraint violation information is lost.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • 1
    Not sure what is happening. Just now tested with SDN 4.1.2 and OGM 2.0.4 - the `org.neo4j.ogm.exception.CypherException` bubbles straight to the top, not wrapped by another exception. There's a feature in the backlog to ensure OGM exceptions are translated to standard Spring exceptions. Able to provide more info? Stack trace? – Jasper Blues Oct 24 '16 at 22:28

0 Answers0