2017-06-10 4 views
0

:私のデータベースで無効な関係

@NodeEntity 
class Account { 
    @GraphId 
    Long id 

    String accountId 
    String firstname 
    String lastname 

    @Relationship(type = 'HAS_INVITED', direction = Relationship.INCOMING) 
    List<Account> invitations = [] 

    String getName() { 
     if (firstname && lastname) { 
      return "$firstname ${lastname[0]}." 
     } 

     return email 
    } 

    @Override 
    int hashCode() { 
     if (id) { 
      return id.hashCode() 
     } else { 
      return 0 
     } 
    } 

    @Override 
    boolean equals(Object obj) { 
     if (obj.is(this)) { 
      return true 
     } 

     if (obj instanceof Account) { 
      return obj.id == id 
     } 

     return false 
    } 

    @Override 
    String toString() { 
     "$email" 
    } 
} 

は、私は2つのアカウントクリスとボブを作成しました。ボブはクリスを以下のように招待しました。アカウントをロードするために enter image description here

が、私はこのリポジトリを書いた:

interface AccountRepository extends GraphRepository<Account> { 
    Account findByAccountId(String id) 

    Account findByEmail(String email) 

} 

さて、私の問題:私は招待として、私はボブを取得クリスアカウントを読み込むとき(それは大丈夫です)。しかし、私はボブのために招待されたクリスを持っているし、なぜ私は理解していない。 私にとっては、クリスには1つの招待状が必要ですが、ボブには1つの招待状が必要です。

+0

あなたは '一覧 invitations'用セッターを持っていますか?その場合は@Relationshipで注釈を付ける必要があります。 –

+0

素晴らしい!できます。 – ChriX

答えて

0

マッピング中のあいまいさを避けるため、INCOMING関係の既存のセッターに注釈を付ける必要があります。これはドキュメントで指定されています。

@Relationshipの方向属性は、デフォルトでOUTGOINGに設定されています。 INCOMING関係でサポートされているフィールドやメソッドには、INCOMING方向で明示的に注釈を付ける必要があります。

http://neo4j.com/docs/ogm-manual/current/reference/#reference:annotating-entities:relationship

+0

ポイントフィールドが欠落していて、セッターメソッドをアノテーションしなければなりません。 – ChriX

関連する問題