问题
I have 2 entities for legacy db with composite keys, one of them has a composite key with @EmbeddedId
annotation.
// 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;
}
How should I define the @OneToOne
relation to join as in the following example:
select p.Id, pd.description
from Product p
inner join p.defects pd
回答1:
I figure out that @MapsId annotation helps in my case http://download.oracle.com/javaee/6/api/javax/persistence/MapsId.html
来源:https://stackoverflow.com/questions/5305687/join-entity-with-composite-key