2016-08-31 2 views
1

私はトップリンクでJPAを作っていて、エンティティクラスを作りたいと思っています。 テーブルBの複合主キー(メッセージ)の外部キーの一部としてテーブルA(エイリアス)PKを使用したいと思います。 私はエンティティのために以下の構造を作成しました。 しかし、私は結合の列はnullと表示nullテーブルに表示されます。FKとして他のテーブルのPKで構成されるコンポジットプライマリキーを作る方法

@Embeddable 
public class MessageEntityPK implements Serializable { 
    private static final long serialVersionUID = -229800894330529492L; 
    private String messageSubject; 
    private String aliasName; 

    public String getMessageSubject() { 
     return messageSubject; 
    } 

    public String getAliasName() { 
     return aliasName; 
    } 

    public MessageEntityPK() { 

    } 

    public MessageEntityPK(String msgSubject, String aliasName) { 
     this.aliasName = aliasName; 
     this.messageSubject = msgSubject; 
    } 
} 

@Entity 
@Table(name = "ALIAS_ENTITY") 
public class AliasEntity { 
    @Id 
    private String aliasName; 
    private String aliasPath; 

    public String getAliasName() { 
     return aliasName; 
    } 

    public void setAliasName(String aliasName) { 
     this.aliasName = aliasName; 
    } 

    public String getAliasPath() { 
     return aliasPath; 
    } 

    public void setAliasPath(String aliasPath) { 
     this.aliasPath = aliasPath; 
    } 

    //hashCode and equals Function. 

} 


@Entity 
public class MessageEntity { 
    @EmbeddedId 
    private MessageEntityPK messageEntityID; 

    @ManyToOne 
    @MapsId("aliasName") 
    @JoinColumn(name = "Alias_Name", referencedColumnName = "aliasName") 
    private AliasEntity aliasEntity; 

    public MessageEntityPK getMessageEntityID() { 
     return messageEntityID; 
    } 

    public void setMessageEntityID(MessageEntityPK messageEntityID) { 
     this.messageEntityID = messageEntityID; 
    } 

    public AliasEntity getAliasEntity() { 
     return aliasEntity; 
    } 

    public void setAliasEntity(AliasEntity aliasEntity) { 
     this.aliasEntity = aliasEntity; 
    } 

} 

表:

| ALIASNAME  | varchar(255) | NO | PRI | NULL |  | 
| MESSAGESUBJECT | varchar(255) | NO | PRI | NULL |  | 
| Alias_Name  | varchar(255) | YES | MUL | NULL |  | 
+----------------+--------------+------+-----+---------+----‌​---+ 
+0

| ALIASNAME | varchar(255)| NO | PRI | NULL | | | | MESSAGESUBJECT | varchar(255)| NO | PRI | NULL | | | Alias_Name | varchar(255)|はいMUL | NULL | | + ---------------- + -------------- + ------ + ----- + --- ------ + ------- + – Abhash

+0

トップリンクとeclipselinkの実装が異なります。私はeclipselink JPAの実装を使用し、私の問題は解決しています。 – Abhash

答えて

0

は私には思えるの注釈発注問題で、最初@MapsId置きます。 参照を参照してください http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#d0e4865

+0

ご返信ありがとうございます。私はjpaを使用していることを理解していない休止状態です。 mapidを使用するときは、FKと同じ1つの余分な列を取得していますが、テーブルの値を入力している間はnull値が入力されています。あなたが見ることができるように2つのエイリアス名の列があります。私はそれを置いてみたが、それでも助けにならない。 – Abhash

+0

私の考えは、最初に実行しているjoinカラムとmapsIdに関するものだった。申し訳ありませんが、あなたを助けることができなかった –

関連する問題