1

实际上,我正在尝试使用 RelationshipEntity 类保存一个节点,如下所示:

  1. 节点类

    @NodeEntity  
    public class MyEvent  
    {  
         @GraphId  
         private Long nodeId;  
         @RelatedToVia(type = "INVITED_TO")  
         @Fetch Set<EventResponse> eventResponse;  
    }
  2. 关系实体类

    @RelationshipEntity(type="INVITED_TO")  
    public class EventResponse  implements Serializable   
    {  
       @GraphId  
       Long nodeId;  
    
       @StartNode  
       MyEvent event;  
    
       @EndNode  
       User user;  
    
      //  .....  
    

    }

当我试图保存MyEvent

org.neo4j.graphdb.NotFoundException: '__type__' property not found for RelationshipImpl #153 of type 15 between Node[159] and Node[117].

所以我猜基于上述异常,它缺少__type__识别任何节点类型所需的某个属性。我不完全明白,有什么方法可以保存第一个关系实体,然后是 NodeEntity,反之亦然,或者同时保存?

4

1 回答 1

3

type属性不需要由您显式设置。它由 spring-data-neo4j 管理。

以下代码片段对我有用:

事件类:

@NodeEntity
public class MyEvent
    {

    @GraphId
    private Long       nodeId;

    @RelatedToVia(type = "INVITED_TO")
    @Fetch
    Set<EventResponse> eventResponse;

    }

用户类:

@NodeEntity
public class User
    {

    @GraphId
    private Long userId;  

    }

和响应类:

@RelationshipEntity(type = "INVITED_TO")
public class EventResponse
    {

    @GraphId
    private Long    nodeId;

    @StartNode
    MyEvent event;

    @EndNode
    User    user;

    }

我在一个简短的junit测试中使用它们:

@Autowired
    private Neo4jTemplate template;

    @Transactional
    @Test
    public void saveEvent()
        {

        User user = new User();
        MyEvent event = new MyEvent();

        EventResponse response = new EventResponse();
        response.user = user;
        response.event = event;

        this.template.save(user);
        this.template.save(event);
        this.template.save(response);

        }
于 2013-08-23T08:02:16.603 回答