monitorjbl
monitorjbl

Reputation: 4350

Unique index in Spring Neo4j not working

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?

Upvotes: 1

Views: 485

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41706

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.

Upvotes: 1

Related Questions