以下のコードはデモ用です。Spring JPA - EmbeddedIdで検索部分的に
マイエンティティ Beanがこの
@Entity
class Employee {
@EmbeddedId
private EmployeeKey employeeKey;
private String firstName;
private String lastName;
// Other fields
// Getter and Setters
}
埋め込みクラスのようになります。
@Embeddable
class EmployeeKey implements Serializable {
private int employeeId;
private String branchName;
private String departmentName;
//Getter and Setters
}
私がいることをEmbeddedIdにより従業員を見つけることJPARepositoryインターフェイスメソッドを書くことができます私も結果を返します。
interface EmployeeRepository extends JpaRepository<Employee, EmployeeKey> {
List<Employee> findByEmployeeKey(EmployeeKey employeeKey);
}
質問: と仮定、照会私ははとbranchNameをEMPLOYEEIDしている、と私はでdepartmentName
- にフィルタをかけたくないしながら、そのような場合、私は自分のリポジトリメソッドを書く方法を教えてください
- JPAにはこのようなシナリオで何かが組み込まれていますか?
http://stackoverflow.com/questions/28020699/how-to-query-on-subsetコンポジットプライマリキー – Zeromus
@Zeromusリンクをありがとう。しかし、私はリポジトリの実装を書くことに賛成ではありません。私は質問に対処するための組み込み機能を利用できるかどうか疑問に思っています –