2016-09-12 11 views
0

にマップされていない、私はこれらの主キーを持つ2つのテーブルがあります。休止OneToManyの関係:単一propery

TABLE A     TABLE B 
    ----------    ----------    
| colA  |----->  | colX  | 
| colB  |----->  | colY  | 
| colC  |----->  | colW  | 
|__________|   | colZ  | 
         |__________| 

を基本的に私はJPA 1.0で、この関係を定義する必要があります。

私はこのコードでにtableAの実体をマッピングしようとした

@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, targetEntity=TableB.class) 
    @JoinColumns({  
      @JoinColumn(name="colX", referencedColumnName="colA", insertable=false, updatable=false), 
      @JoinColumn(name="colY", referencedColumnName="colB", insertable=false, updatable=false), 
      @JoinColumn(name="colW", referencedColumnName="colC", insertable=false, updatable=false) 
     })  

private Set<TableB> tableB; 

..get and set 

私が得るすべては、このエラーです:

org.hibernate.AnnotationException: Unable to map collection TableB 

    Caused by: org.hibernate.AnnotationException: referencedColumnNames(colA, colB, colC) of tableB referencing tableA not mapped to a single property 

任意のヘルプ?

EDIT *

どちらの表AとテーブルBは、上に述べた自らのPK colsので@EmbeddedId主キークラスを得ました。

以下のコードは、あなたのマッピングが部分的に間違っているような状況に

// TABLE A PKey Entity 

@Embeddable 
class TableAPKey 
{ 
    @Column 
    String colA; // get and set 
    @Column 
    String colB; // get and set 
    @Column 
    String colC; // get and set 
} 

// TABLE A Entity 

class TableA 
{ 
    @EmbeddedId 
    TableAPKey key; // get and set 
} 
// TABLE B PKey entity 

@Embeddable 
class TableBPKey 
{ 
    @Column 
    String colX; // get and set 
    @Column 
    String colY; // get and set 
    @Column 
    String colW; // get and set 
    @Column 
    String colZ; // get and set NOT USED IN RELATIONSHIP with TableA 
} 

// TABLE B Entity 

class TableB 
{ 
    @EmbeddedId 
    TableBPKey key; // get and set 
} 
+0

'colA'、' colB'、 'colC'は' TableA'の複合主キーですか? 'TableA'エンティティのIDフィールドを投稿してください。 –

+0

エンティティAとBの定義を挿入して質問を改善しました –

+0

BとAとの関係はありますか? –

答えて

0

を良く説明しています。以下を試してください:

class TableA { 

    // ... 
    @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, targetEntity=TableB.class, mappedBy = "key.tableA") 
    private Set<TableB> tableB; 
} 


@Embeddable 
class TableBPKey { 

    @ManyToOne 
    @JoinColumns({ 
     @JoinColumn(name = "colX", referencedColumnName = "colA"), 
     @JoinColumn(name = "colY", referencedColumnName = "colB") 
     @JoinColumn(name = "colW", referencedColumnName = "colC") 
    })   
    private TableA tableA; 

    @Column 
    String colZ; 

    // ... 
} 
+0

では「キー」はありません。 tableAまたはtableB主キーを指していますか? –

+0

'Set 'を参照すると 'TableB'の' key'を意味します。 – Smutje

+0

それは動作しません:( –