Reputation: 539
i have an Entity with following mappings:
@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;
The Template Bean looks as following:
@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;
The Problem im facing is, im very untrained when it comes down to use the JPA Interfaces.
How can i use these to get the following query:
select template
from Template template
join TemplateProductBean templateProducts
on template.templateId = templateProducts.template.templateId
where templateProducts.productId in :templateProductIdList
How can i use the JPA Interfaces( javax.persistence.criteria.Root, javax.persistence.Join etc.) to build this query as a Predicate? I'm sorry if im being unclear, i have to use this and im not used to using the JPA. Thanks
Upvotes: 1
Views: 2030
Reputation: 24433
I think this should work
select t from TemplateBean t inner join t.templateProductBean tpb where tpb.productId in :templateProductIdList
More details on inner joins and HQL in general: documentation
Upvotes: 1