Hibernate 用于排序的弹簧规格左连接
我有下面的实体,想知道如何使用JPA规范创建下面的查询Hibernate 用于排序的弹簧规格左连接,hibernate,spring-boot,jpa,spring-data-jpa,jpa-criteria,Hibernate,Spring Boot,Jpa,Spring Data Jpa,Jpa Criteria,我有下面的实体,想知道如何使用JPA规范创建下面的查询 SELECT p.* FROM property p INNER JOIN ad ON ad.id = p.ad_id LEFT JOIN featured_ad fad ON fad.id = ad.id ORDER BY fad.start_date DESC, ad.created_ts DESC 实体(已删除方法和其
SELECT p.*
FROM property p
INNER JOIN ad
ON ad.id = p.ad_id
LEFT JOIN featured_ad fad
ON fad.id = ad.id
ORDER BY fad.start_date DESC,
ad.created_ts DESC
实体(已删除方法和其他属性以简化类):
我可以用add连接属性,但用featuredAd连接属性,然后按其开始日期排序是我无法理解的
specification = specification.and(new Specification<Property>() {
@Override
public Predicate toPredicate(Root<Property> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
final Join<Ad, Property> adProperty = root.join("ad", JoinType.INNER);
//how to join to featuredAd the order by startDate?
// what to return here?
}
});
specification=规范和(新规范(){
@凌驾
公共谓词toPredicate(根根、CriteriaQuery cq、CriteriaBuilder cb){
final Join adProperty=root.Join(“ad”,JoinType.INNER);
//如何通过startDate加入订单的功能?
//在这里返回什么?
}
});
将一个从属性到功能的关联添加到FeatureAd,以建立双向关联。感谢回复@K.Nicholas。ad和featuredAd之间已存在关联。我不想在featuredAd和property之间再添加一个。您有一个单向关联,但您想转到另一个方向。我猜佐罗的剑有点钝了。
specification = specification.and(new Specification<Property>() {
@Override
public Predicate toPredicate(Root<Property> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
final Join<Ad, Property> adProperty = root.join("ad", JoinType.INNER);
//how to join to featuredAd the order by startDate?
// what to return here?
}
});