1
我現在面臨一個問題,QueryDSL 4.0.5和多個連接。 我有兩個班級:多與同桌加入QueryDSL冬眠
public class Users {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@Column(nullable = false)
private String username;
}
public class Ranking {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@Column(nullable = false)
private Date date;
@Column(nullable = false)
private Integer rank;
@Column(nullable = false)
private Integer point;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seller_id")
private Users user;
}
某些用戶是賣家並且有排名。
我想要做的是讓每一個用戶,他的身份證和名字,以及他在2015-12-01 00:00:00
(其中存在一定,由於我的項目)的排名和他的2015-12-01 00:00:00
等級(可能爲null) (日期對於EG)
所以在SQL(這完全正常工作):
SELECT u.id, u.username, r.rank, r2.rank
FROM USERS u
INNER JOIN ranking r ON u.id=r.seller_id AND r.date = '2015-12-01 00:00:00'
LEFT OUTER JOIN ranking r2 ON u.id=r2.seller_id AND r2.date = '2015-10-28 00:00:00'
ORDER BY r.rank
但是,當我想要做queryDSL這一要求,它不工作... 這裏我的代碼: 我已經因爲多個兩QRanking
加入與相同的TA BLE)
private static final QSeller SELLER = QSeller.seller;
private static final QRanking RANKING = QRanking.ranking;
private static final QRanking RANKING_OLD = new QRanking("old");
queryFactory.from(SELLER)
.select(SELLER.id, SELLER.username, RANKING.point, RANKING.rank, RANKING_OLD.rank)
.innerJoin(RANKING.seller).on(RANKING.campaign.id.eq(campaignId).and(RANKING.date.eq(last)))
.leftJoin(RANKING_OLD.seller).on(RANKING_OLD.campaign.id.eq(campaignId).and(RANKINGY_OLD.date.eq(secondToLast)))
.orderBy(RANKING.rank.asc())
.fetch();
這裏的日誌摘錄:
org.hibernate.hql.internal.ast.InvalidPathException: Invalid path: 'ranking.seller'
org.hibernate.hql.internal.ast.InvalidPathException: Invalid path: 'ranking.point'
org.hibernate.hql.internal.ast.InvalidPathException: Invalid path: 'ranking.rank'
org.hibernate.hql.internal.ast.InvalidPathException: Invalid path: 'old.rank'
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'ranking.seller'
我怎樣才能解決這個問題呢?
感謝,