无法保存@RelationshipEntity

时间:2012-03-27 12:53:41

标签: java nosql neo4j spring-data-neo4j

我试图保存一些@RelationshipEntity: 我有问卷,每个问卷都与一些问题有关。 首先,我尝试了如下:

@RelatedToVia
private Set<HasQuestionRelationship> question = new HashSet<HasQuestionRelationship();

并保存根。这让我想到了这个问题: http://forum.springsource.org/showthread.php?124316-Spring-Data-Neo4j-NullPointerException-with-RelatedToVia以及此问题https://jira.springsource.org/browse/DATAGRAPH-216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel#issue-tabs

然后我试图只保存一个关系:

@RelatedToVia(elementClass=HasQuestionRelationship.class, type="HAS_QUESTION", direction=Direction.OUTGOING)
private HasQuestionRelationship question2;

我的关系类看起来像:

@RelationshipEntity(type="HAS_QUESTION")
public class HasQuestionRelationship {
    @GraphId
    Long id;

    private String name;

    @StartNode
    private QuestionnaireNode questionnaire;

    @EndNode
    private QuestionNode question;

    public HasQuestionRelationship() {
    }

    public HasQuestionRelationship(QuestionnaireNode questionnaireNode,
            QuestionNode question, String string) {
        if (question == null)
            System.out.println("csxa");
        this.questionnaire = questionnaireNode;
        this.question = question;
        this.name = string;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public QuestionnaireNode getQuestionnaire() {
        return questionnaire;
    }

    public void setQuestionnaire(QuestionnaireNode questionnaire) {
        this.questionnaire = questionnaire;
    }

    public QuestionNode getQuestion() {
        return question;
    }

    public void setQuestion(QuestionNode question) {
        this.question = question;
    }

}

我的班级问卷如下:

public class QuestionnaireNode extends BaseNode {
    @RelatedToVia(elementClass=HasQuestionRelationship.class, type="HAS_QUESTION", direction=Direction.OUTGOING)
    private HasQuestionRelationship question2;

    public QuestionnaireNode() {}

    public QuestionnaireNode(String name) {
        setName(name);
    }

    public QuestionnaireNode(String name, QuestionNode question) {
        setName(name);
        this.question2 = new HasQuestionRelationship(this, question, "testrelation");
    }

    public HasQuestionRelationship getQuestion2() {
        return question2;
    }

    public void setQuestion(HasQuestionRelationship question) {
        this.question2 = question;
    }
}

现在,我试图保存一些testdata:

    QuestionNode question = new TextQuestionNode("question");
    QuestionnaireNode questionnaire = new QuestionnaireNode("questionnaire");
    HasQuestionRelationship relationtype = new HasQuestionRelationship(questionnaire, question, "mytest");
    questionnaire.setQuestion(relationtype);


    try {
        myRepository.save(question);
        myRepository.save(questionnaire);
    } catch (Exception e) {

        e.printStackTrace();
    }

不会抛出任何异常。我很高兴,但如果我查看我的数据库,我只看到2个节点,但它们之间没有任何关系。我的错在哪里?

由于

0 个答案:

没有答案