【发布时间】:2017-08-11 13:25:38
【问题描述】:
我的 HQL 请求
SELECT p FROM Payment p
LEFT JOIN FETCH p.paymentProperties pr ON p.id = pr.payment.id
WHERE
p.user.id = :userId ORDER BY id DESC
数据类实体
@Entity
@Table (name = "t_payment")
public class Payment {
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne (cascade = CascadeType.DETACH)
@JoinColumn (name = "user_id", nullable = false)
private User user;
@OneToMany (mappedBy = "payment", fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.DETACH})
private List<PaymentProperty> paymentProperties;
}
@Entity
@Table (name = "t_payment_property")
public class PaymentProperty {
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne (fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.DETACH})
@JoinColumn (name = "payment_id", nullable = false)
private Payment payment;
}
@Entity
@Table (name = "t_user")
public class User {
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
private Long id;
}
结果异常:QuerySyntaxException: with-clause not allowed on fetched associations;使用过滤器
任何想法都必须在不删除 fetch 的情况下修复它?
【问题讨论】:
标签: java postgresql hibernate hql