0
我們使用jpa/hibernate,但是我們有一些像這樣的本地查詢。將嵌套的sql查詢轉換爲jpa/hibernate
SELECT cp1.id AS customerbookid
FROM customerbook cp1
INNER JOIN customer cu ON cu.id = cp1.customerid
WHERE cp1.autoRenew='Y'
AND cp1.endTime < now()
AND
(SELECT cp2.customerid
FROM customerbook cp2
WHERE cp1.customerid=cp2.customerid
AND cp2.startTime > now()
) IS NULL
映射
@Entity
@Table(name = "customerbook")
public class CustomerBook{
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "customerId")
private long customerId;
@Column(name = "startTime")
private Timestamp startTime;
@Column(name = "endTime")
private Timestamp endTime;
@Column(name = "autoRenew")
private Character autoRenew;
}
@Entity
@Table(name = "customer")
public class customer{
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
是否有可能將其轉換爲JPA?
您是否指向JPQL? –
是JPQL。我們可以用jpa使用hql嗎? – redfox26
'JPA'是一個'API'。 'Hibernate'是JPA **實現**之一。 'HQL'是Hibernate特定的語言。 –