2017-10-03 7 views
0

私はbo_operatorhist_bo_operator_passwordと2つのテーブルforeign keys id_operator bigint REFERENCES bo_operator(id)を持っています。 hist_bo_operator_passwordには、id_operatorのパスワードが多数あります。今私は春のブートアプリケーションのすべての値をList<String>に持っていきたいと思います。 は、これまでのところ私が持っている:id_operatorためhist_bo_operator_passwordからすべてのパスワードを返すようにリストを取得<String>データベースから休止状態に

@Column(table="hist_bo_operator_password", name="password") 
public List<String> getOldPasswords() 
{ 
    return 
} 

@Entity 
@Table(name="bo_operator") 
@SecondaryTable(name = "hist_bo_operator_password", [email protected](name="id_operator", referencedColumnName="id")) 
public class Operator { 
    public Operator(Long id) { 
     super(); 
     this.id = id; 
    } 

にはどうすればメソッドを書くことができますか?

+0

特に、オペレータと強く結びついている場合は、別のテーブルの1つの列に対して新しいクラスを追加する必要はありません。この列をOperatorクラスに入れたいのですが、1つのテーブル= 1つのエンティティというルールを壊していますか? – Michu93

+1

'@ SecondaryTable'は、1つのエンティティの情報が2つのテーブルに分散されている「onetoone」関係のために主に使用されているので、これを行うことはできません。私はリンクされた答えで述べたように '@ ElementCollection'アノテーションを使う必要があると思います。 – g00glen00b

+0

@ElementCollection \t @CollectionTable(名前= "hist_bo_operator_password"、joinColumns = @ JoinColumn(名前= "id_operator")) \t @Column(名= "パスワード") \t公共一覧 oldPasswords =新しいArrayListを(); は上記のような問題を解決しました – Michu93

答えて

1

@ElementCollectionでは、非Entityクラスのマッピングを定義することができます。また、@CollectionTableを使用してテーブルを定義することもできます。