2017-11-28 7 views
-1

私は多くのSpring Repositoryインタフェースを使用しています。 1つは私のために正常に働いていたが、私はそれからもう少し必要があることを理解した。私は、get()、私はコピー&ペーストうまくいけば、次はそれを分かりやすくするために十分な情報を与えることができないので、イントラネット上で動作Springリポジトリ投影1つのオブジェクトの子を取得

の1つの以上のレベル...

@Entity 
@Table(name="person") 
class Person { 
    ... 
} 

@Entity 
@Table(name="requisite") 
class Requisite { 
    ... 
    @OneToOne 
    @JoinColumn 
    private Document document; 
} 

@Entity 
@Table(name="person_requisite") 
class PersonRequisite { 
    ... 
    @ManyToOne 
    @JoinColumn(name="person_id") 
    private Person person; 
    ... 
    @ManyToOne 
    @JoinColumn(name="requisite_id") 
    private Requisite requisite; 
    ... 
} 

@Projection(name="personRequisiteProjection", types={PersonRequisite.class}) 
public interface PersonRequisiteProjection { 
    ... 
    Person getPerson(); 
    Requisite getRequisite(); 
    ... 
} 

ここに行きたかったです...ここで

"personRequisites" : [ { 
    ... 
    "requisite" : { 
    id : 1, 
    ... 
    no document object or document id from the requisite 
    }, 
    "person" : { 
    id : 33, 
    ... 
    }, 
    ... 
] 
... 

は、私が何をしたいの表現私は今取得しています何の表現です...

"personRequisites" : [ { 
    ... 
    "requisite" : { 
    id : 1, 
    ... 
    "document" : { 
     "id" : 55, 
     "name" : blah, 
     ... 
    } 
    }, 
    "person" : { 
    id : 33, 
    ... 
    }, 
    ... 
] 
... 

私は、これは正しくありません知っているが、私は基本的に

@Projection(name="personRequisiteProjection", types={PersonRequisite.class}) 
public interface PersonRequisiteProjection { 
    ... 
    //i know, this would be out of place if it worked but trying to emphasize what i want... 
    Document getRequisite().getDocument(); 
    //i'd still want Requisite getRequisite() as well but you get what i am after 
    ... 

    //or more appropriately, force document to show up in Requisite here... 
    Requisite getRequisite(); 
    ... 
} 
+0

チェックをしたい、このくださいhttps://stackoverflow.com/questions/44554979/how-to-loop-and-retrieve-value-from- hateoas-link-attribute-eg-retrieve-a-des/44564464#44564464 –

+0

どのような冗談です。あなたが上記のリンクに実際に1つを導くだろうか?何かが人々に深刻に間違っている。彼らは嫌悪者です。神があなたを世話してくれます。 – user2052618

答えて

1
@Projection(name="personRequisiteProjection", types={PersonRequisite.class}) 
public interface PersonRequisiteProjection { 
    ... 
    @Value("#{target.requisite.document}") 
    Document getRequisite().getDocument(); 
    //i'd still want Requisite getRequisite() as well but you get what i am after 
    ... 

    //or more appropriately, force document to show up in Requisite here... 
    Requisite getRequisite(); 
    ... 
} 
+0

これは機能しました! 1つの小さなことは、getRequisite()を行うことができないということです。getDocument()は何がうまくいくかを知ることができます。あなたが言及したようにgetDocument()をドキュメント化して注釈を付けてください。だから私の問題はあまりにも多くのデータです。 Documentオブジェクトにはドキュメントのバイナリがあり、それも元に戻ります。私はおそらくちょうど値の注釈で必要なドキュメントの部分を取得する必要があります。これは、ドキュメントをディスクに置く必要があることを示し、データベースにはドキュメントへのポインタがあります。我々はこれについて議論しましたが、少なくとも今はそれをしないと考えました。 – user2052618

+0

私はJsonIgnoreをドキュメントバイナリを持つフィールドに追加しました。だからすべてが再び壮大です!ありがとう! – user2052618

+0

素晴らしい、あなたは歓迎です:) –

関連する問題