我正在尝试在我的一个JPA存储库中选择内部联接
查询:
@Query(value = "select wm.WagerIdentification, wm.BoardNumber, wm.MarkSequenceNumber, wm.MarkNumber," +
" pt.CouponTypeIdentification, pt.WagerBoardQuickPickMarksBoard " +
"from WagerBoard wb " +
"inner join wb.listOfWagerMarks wm on wb.WagerIdentification = wm.WagerIdentification and wb.BoardNumber = wm.BoardNumber and wb.GameIdentification = wm.GameIdentification and wm.meta_IsCurrent = 1 " +
"inner join wb.poolgameTransaction pt on (wb.TransactionIdentification = pt.TransactionIdentification and pt.meta_IsCurrent = 1)" +
"where wb.meta_IsCurrent = 1")
List<Object[]> findAllTest();
关系:
PoolgameTransactions
@OneToMany(mappedBy = "poolgameTransaction")
private List<WagerBoard> ListOfWagers = new ArrayList<>();
WagerBoard
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "TransactionIdentification", insertable = false, updatable = false),
@JoinColumn(name = "meta_CreatedDate", insertable = false, updatable = false)
})
private PoolgameTransaction poolgameTransaction;
@OneToMany(mappedBy = "wagerBoard")
private List<WagerBoardMarks> listOfWagerMarks;
WagerBoardMarks
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "BoardNumber", insertable = false, updatable = false),
@JoinColumn(name = "GameIdentification", insertable = false, updatable = false),
@JoinColumn(name = "WagerIdentification", insertable = false, updatable = false),
@JoinColumn(name = "meta_CreatedDate", insertable = false, updatable = false)
})
private WagerBoard wagerBoard;
错误:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause referenced two different from-clause elements
答案 0 :(得分:1)
我会将条件从On ..移到where部分:
select wm.WagerIdentification, wm.BoardNumber, wm.MarkSequenceNumber, wm.MarkNumber," +
" pt.CouponTypeIdentification, pt.WagerBoardQuickPickMarksBoard " +
"from WagerBoard wb " +
"inner join wb.listOfWagerMarks wm
"inner join wb.poolgameTransaction pt
where wm.meta_IsCurrent = 1 and wb.meta_IsCurrent = 1
无论如何,其他依赖项隐式嵌入到映射配置中。
答案 1 :(得分:0)
请勿在查询中使用ON。请尝试以下操作:
@Query(value = "select wm.WagerIdentification, wm.BoardNumber, wm.MarkSequenceNumber, wm.MarkNumber," +
" pt.CouponTypeIdentification, pt.WagerBoardQuickPickMarksBoard " +
"from WagerBoard wb " +
"inner join wb.listOfWagerMarks wm where wb.WagerIdentification = wm.WagerIdentification and wb.BoardNumber = wm.BoardNumber and wb.GameIdentification = wm.GameIdentification and wm.meta_IsCurrent = 1 " +
"inner join wb.poolgameTransaction pt where (wb.TransactionIdentification = pt.TransactionIdentification and pt.meta_IsCurrent = 1)" +
"where wb.meta_IsCurrent = 1")
List<Object[]> findAllTest();