У меня есть 2 сущности для устаревшей БД с составными ключами, один из них имеет составной ключ с аннотацией @EmbeddedId
.
// first entity
@Entity
public class Product {
@Id
private Integer productId;
// lookup table contains code-description pairs
@OneToOne
private ProductDefects defects;
//getters and setters and other code omitted
}
// lookup entity
@Entity
public class ProductDefects {
@EmbededId
private ProductDefectsPK id;
//getters and setters and other code omitted
}
//composite key
@Embedable
public class ProductDefectsPk{
private Integer realId;
private String category;
}
Как определить отношение @OneToOne
для объединения, как вследующий пример:
select p.Id, pd.description
from Product p
inner join p.defects pd