Clicky

Hibernate - Criteria Inner Join

November 12, 2015

Build an Inner Join in Hibernate:

Solution:

@Entity
@Table(name = “shop_product_uid”)
public class ShopProductUid {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = “shop_product_id”)
private ShopProduct shopProduct;
@Column(name = “shop_product_uid”)
private String shopProductUid;
@ManyToOne
@JoinColumn(name = “shop_product_uid_type_id”)
private ShopProductUidType shopProductUidType;

Criteria criteria = session.createCriteria(ShopProductUid.class)
criteria.createAlias(“shopProductUidType”, “shopProductUidType”) // inner join by default
.add(Restrictions.eq(“shopProductUidType.typeId”, parameterTypeId));