2016-09-08 10 views
0

フォルダ(単純な主キー)と文書(複合主キー)
2つのテーブルのIDを含むfolder_documentsという名前の結合テーブルが必要です私のエンティティの列jpa複数の列と複合キーを追加

あり:

フォルダ

@Entity 
@Table(name = "folder") 

public class Folder { 

    @Id 
    @SequenceGenerator(name = "folder_seq_gen", sequenceName = "FOLDER_SEQ", allocationSize = 1) 
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "folder_seq_gen") 
    private long id; 

    @Column 
    private Date date; 

    @OneToMany(mappedBy = "folder_documents_compositeKey.folder", 
      cascade = CascadeType.ALL) 
    private Set<Folder_Documents> folder_documents; 

ドキュメント

@Entity 
@Table(name="document") 
public class Document { 

    @EmbeddedId 
    private DocumentID documentCompositeKey; 

    @Column 
    private Date date; 

文書ID(複合キー)

@Embeddable 
public class DocumentID implements Serializable { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    private String id; 
    private String matricule; 

Folder_Document(結合テーブル)

@Entity 
@Table(name = "folder_documents") 
@AssociationOverrides({ 
    @AssociationOverride(name = "folder_documents_compositeKey.folder", 
     joinColumns = @JoinColumn(name = "folder_id")), 
    @AssociationOverride(name = "folder_documents_compositeKey.document", 
     joinColumns = @JoinColumn(name = "doc_id" , referencedColumnName = "id")), // error mapping there 
    @AssociationOverride(name = "folder_documents_compositeKey.document", 
     joinColumns = @JoinColumn(name = "matricule" , referencedColumnName = "matricule"))})// error mapping there 
public class Folder_Documents { 

    @EmbeddedId 
    private Folder_Documents_ID folder_documents_compositeKey = new Folder_Documents_ID(); 

    @Column 
    private Date date; 

    @Column 
    private String status; 

Folder_documents_id(複合キー)が

@Embeddable 
public class Folder_Documents_ID implements Serializable { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    @ManyToOne(cascade = CascadeType.ALL) 
    private Folder folder; 
    @ManyToOne(cascade = CascadeType.ALL) 
    private Document document; 

問題は、私はDocumentをマッピングすることはできませんです複合キーがFolder_Documents@AssociationOverridesの属性であるため、hibernate d複合キーのidとmatriculeのプロパティはDocumentにありません。フォルダ参照は問題ありません。

ありますが、スタックトレースです:

Caused by: org.hibernate.AnnotationException: referencedColumnNames(matricule) of com.renault.entity.Folder_Documents_ID.folder_documents_compositeKey.document referencing com.renault.entity.Document not mapped to a single property 

答えて

0

が解決、AssociationOverride注釈の構文が間違っていた

正しい構文:

AssociationOverrides({ 
    @AssociationOverride(name = "folder_documents_compositeKey.folder", joinColumns = @JoinColumn(name = "folder_id")), 
    @AssociationOverride(name = "folder_documents_compositeKey.document", joinColumns = { 
      @JoinColumn(name = "doc_id" , referencedColumnName = "id") , 
      @JoinColumn(name = "matricule" , referencedColumnName = "matricule") })}) 
関連する問題