0

前回ログに記録したユーザーを別のテーブルに保存したいとします。私はLOG_INFOテーブルを作成し、それをたLogInfoクラス:複合クラスでメッセージを受け取るのはなぜですか?

@Entity 
@Table(name="log_info") 
public class LogInfo { 

    @Id 
    @OneToOne 
    @JoinColumn(name="user_id") 
    private Accountant id; 

    public LogInfo(){} 

    public LogInfo(Accountant user){ 
     id = user; 
    } 

    public Accountant getId() { 
     return id; 
    } 

    public void setId(Accountant userId) { 
     this.id = userId; 
    } 

} 

マイ会計士クラスは次のとおりです。

@Entity 
@Table(name="accountant") 
public class Accountant { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name="accountant_id") 
    private int id; 

    @Column(name="name") 
    private String name; 

    @Column(name="surname") 
    private String surname; 

    @Column(name="mail") 
    private String mail; 

    @Column(name="avatar") 
    private String avatar; 

    @Column(name="phone") 
    private String phone; 

    @ManyToOne 
    @JoinColumn(name="interface_lang_id") 
    private Languages interfaceCode; 

    public Accountant(){} 

    public Accountant(String name, String surname, String mail, String phone, Languages interfaceLang, String avatar){ 
     this.name = name; 
     this.surname = surname; 
     this.mail = mail; 
     this.avatar = avatar; 
     this.phone = phone; 
     this.interfaceCode = interfaceLang; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getSurname() { 
     return surname; 
    } 

    public void setSurname(String surname) { 
     this.surname = surname; 
    } 

    public String getMail() { 
     return mail; 
    } 

    public void setMail(String mail) { 
     this.mail = mail; 
    } 

    public String getAvatar() { 
     return avatar; 
    } 

    public void setAvatar(String avatar) { 
     this.avatar = avatar; 
    } 

    public String getPhone() { 
     return phone; 
    } 

    public void setPhone(String phone) { 
     this.phone = phone; 
    } 

    public Languages getInterfaceCode() { 
     return interfaceCode; 
    } 

    public void setInterfaceCode(Languages interfaceCode) { 
     this.interfaceCode = interfaceCode; 
    } 

} 

これは、データベースの構造です:

enter image description here

LOG_INFOテーブルます最後にログインしたユーザーのレコードは1つだけです。私は私のアプリケーションを実行しようとしたときに私は例外があります:org.hibernate.MappingException: Composite-id class must implement Serializable: home.accounting.model.LogInfoなぜ私は1つの列を持っていますが、この例外が表示されますか?

+0

https://stackoverflow.com/a/9276253/3959856 –

+0

しかし、私は '@ Id'を1つしか持っていません – Alyona

+0

' LogInfo'のあなたのId列は 'Accountant'のタイプです –

答えて

関連する問題