0
我有一個實體類LeaseRequest與子類作爲pendingUsers像下面。在休眠狀態下的子對象列表的條件查詢
LeaseRequest.java
@Entity
public class LeaseRequest implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CTC_AC_LEASE_PENDING_USER", joinColumns = {@JoinColumn(name = "LeaseRequestId")}, inverseJoinColumns = {@JoinColumn(name = "userId")})
@Cascade(value = org.hibernate.annotations.CascadeType.ALL)
private Set<User> approvers = new HashSet<User>();
@Column(name = "active", nullable = false, columnDefinition = "varchar default 'Y'")
@org.hibernate.annotations.Type(type = "yes_no")
private boolean active = true;
@NotBlank
@Column(nullable = false, unique = true)
private String poNo;
}
User.java
public class User{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private int id;
@NotBlank(message = "User ID cannot be empty")
@Column(unique = true, nullable = false, updatable = false)
private String userId;
}
我想找回這給了用戶ID作爲審批者一個都LeaseRequest對象。如何用hibernate Criteria寫這篇文章?
我寫下如下,當我有一對一的映射。
createEntityCriteria()
.add(Restrictions.eq("approvers.userId", userId))
.add(Restrictions.eq("active", true)).list();
因爲我們現在變成了多對多的映射如何實現這一目標?