NodeBacked entity NPE - entityState is null

我的未来我决定 提交于 2019-12-24 16:18:18

问题


I've got a sample project which uses Spring Data Neo4j's advanced mapping using aspectj. It's failing in a test with NullPointerException due to the entityState attribute being null at the time when the entity is being persisted.

I can also replicate this when the server itself is spun up and I execute:

curl -i -X POST -H "Content-Type:application/json" -d '{  "firstName" : "Test",  "lastName" : "Person" }' http://localhost:8080/people

The project is at https://github.com/dhallam/spring-data-neo4j-demo and the Travis build with the logs is at https://travis-ci.org/dhallam/spring-data-neo4j-demo/builds/22538972.

I'm not sure whether I'm missing something or there is a bug that would require me to raise a JIRA issue.

Any ideas? Many thanks in advance.

Edit 1:

Versions: Java v1.7; SDNeo4j v3.1.0.M1; SDRest v2.1.0.M1; Neo4j v2.0.1; Jetty v9.0.5.v20130815; AspectJ v1.7.4

Tried adding @JsonIgnoreProperties to the Person (@NodeEntity)from Michael's comment below and it's still failing. The bit of code that is failing is when I run:

Person p = new Person();
// setters ...
p.persist();

The persist() calls

public <T extends NodeBacked> T NodeBacked.persist() {
    return (T)this.entityState.persist();
}

but entityState is null.


回答1:


Figured it out. The Neo4jConfig class previously extended the Neo4jConfiguration class. With the introduction of aspects, that superclass needed to be updated to be Neo4jAspectConfiguration to provide the additional neo4jRelationshipBacking and neo4jNodeBacking beans.

I've updated the github reference project at https://github.com/dhallam/spring-data-neo4j-demo and the build is passing.




回答2:


Which versions do you use?

You can use @JsonIgnore for the entityState attribute.

See: http://forum.spring.io/forum/spring-projects/data/nosql/110063-unable-to-convert-nodeentity-object-to-json-with-jackson

@JsonIgnoreProperties({"entityState", "nodeId", "persistentState", "relationshipTo", "template"})


来源:https://stackoverflow.com/questions/22945171/nodebacked-entity-npe-entitystate-is-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!