1

I know that from the title, this sound like a duplicate of this question, but I promise you it isn't. In fact, the @Indexed(unique=true) is working correctly in that it duplicates are being caught! However, when creating the first node, Spring is actually creating two nodes somehow. Here is what I'm doing:

@Autowired
private MyEntityRepository repo;

public void testCreate(){
    MyEntity me = new MyEntity();
    me.setName("somename");
    me.setDescription("blah blah");
    repo.save(me);
}

@NodeEntity
public class MyEntity{
    @GraphId
    private Long id;
    @Indexed(unique=true)
    private String name;
    private String description;
}

After this runs on an empty database, an DataIntegrityViolationException will be thrown and two nodes are created. The one with the lowest ID will have the name and description fields on it, but the other node will only have the name field. Weirdly, the name fields have the same value in both nodes, so even though the exception was thrown, it still tried to make the node. If I take off the @Indexed annotation, everything works correctly and only one node gets created (but obviously there is no duplicate prevention).

I am using a standalone Neo4j server, because several other pieces of this application need to be able to access it. However, I have noted that this behavior does not occur with the embedded Neo4j server. I'm really hoping that such a useful feature is supported in Spring over HTTP, but I wouldn't be all that surprised if it didn't. Is there a way to make this work?

Community
  • 1
  • 1
monitorjbl
  • 4,280
  • 3
  • 36
  • 45

1 Answers1

1

Spring Data Neo4j over HTTP doesn't really use transactions. What SDN version do you use?

I tries to use the unique creation facilities of Neo4j server and usually that works.

Can you share your full stack trace and perhaps check the server logs for any issues.

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • I'm using 2.3.2.RELEASE right now. I'd gathered that transactional support isn't there yet, although Neo4j supports it over HTTP, so hopefully SDN will soon. I've noticed a number of things not being supported over HTTP in SDN, but this one was just bizarre. – monitorjbl Jan 02 '14 at 14:49
  • There are only transactions over http in Neo4j 2.0 and only for cypher. So that will only come after a massive rewrite of the underpinnings of SDN. I still would like to see your stacktrace and perhaps a standalone test project that reproduces the issue. – Michael Hunger Jan 02 '14 at 23:58