我有一个包含以下映射的实体:
@Entity
@Table(name = "template_product")
public class TemplateProductBean implements Serializable {
private static final long serialVersionUID = -1821696115330320798L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name = "product_id")
private Long productId;
// bi-directional many-to-one association to
// Template
@ManyToOne
@JoinColumn(name = "template_id")
private TemplateBean template;
模板Bean如下所示:
@Entity
@Table(name = "template")
public class TemplateBean implements Serializable {
private static final long serialVersionUID = 3752018564161042623L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "platform_id")
private Long platformId;
@Column(name = "template_name")
private String templateName;
// bi-directional many-to-one association to
// TemplateProduct
@OneToMany(mappedBy = "template")
private List<TemplateProductBean > templateProductBean;
我面临的问题是,在使用JPA接口时我是非常未经训练的。
如何使用这些来获得以下查询:
select template
from Template template
join TemplateProductBean templateProducts
on template.templateId = templateProducts.template.templateId
where templateProducts.productId in :templateProductIdList
如何使用JPA接口(javax.persistence.criteria.Root,javax.persistence.Join等)将此查询构建为谓词?我很抱歉,如果我不清楚,我必须使用这个,我不习惯使用JPA。感谢
答案 0 :(得分:1)
我认为这应该有用
select t from TemplateBean t inner join t.templateProductBean tpb where tpb.productId in :templateProductIdList
有关内部联接和HQL的更多详细信息:documentation