问题
I'm trying to select with a inner join in one of my JPA repositories
the query:
@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();
relations:
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;
the error:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause referenced two different from-clause elements
回答1:
I would remove the condition from On.. to the where part:
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
The other dependencies are implicitly embedded in the mapping configuration anyway.
回答2:
Do not use ON in your query.Try the following:
@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();
来源:https://stackoverflow.com/questions/42410950/jpa-spring-boot-inner-join-with-clause-referenced-two-different-from-clause-el