在我的应用程序中,我有三个类用嵌入式类相互链接。
ID为Id的Ordine类
@Entity
@Table(name = "ordine")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Ordine implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ordine_id")
private Long id;
@Column(name = "company_id")
private Long companyId;
....
ID为嵌入式ID的OrdineUtente类
@Entity
@Table(name = "ordini_vettori")
@AssociationOverrides({
@AssociationOverride(name = "id.ordine", joinColumns = @JoinColumn(name = "ordine_id")),
@AssociationOverride(name = "id.utente", joinColumns = @JoinColumn(name = "utente_id")) })
public class OrdineUtente implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private OrdineUtenteId id;
@Column(name = "sort_order")
private Integer sortOrder;
....
}
和可嵌入类OrdineUtenteId
@Embeddable
public class OrdineUtenteId implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne
private Ordine ordine;
@ManyToOne
private UserApp utente;
....
}
如何使用Hibernate中的join来查找与我们的订单相关联的所有用户?
我试着写这个查询:
SELECT ordine FROM Ordine ordine
LEFT JOIN OrdineUtente ordineUtente
WHERE ordine.id = ordineUtente.id.ordine.id
AND ordineUtente.id.utente.userId = :userId
但它不正确,因为缺少连接值。 :userId
参数从外部传递。