JPA查询:加入问题

JPA查询:加入问题,jpa,jpql,Jpa,Jpql,我有一个JPA问题: <named-query name="AUDIT_QUERY"> <query> select rx.rxNumber, rx.rxFillStatus.id, tx.rx.rxaaId, tx.id, tx.drugUpc.id, tx.compound.id, tx.tpSpecialServiceFee.id,tx.txHistoryDrugUpc.id, tx.txHistoryCompound.id, tx.txHistoryT

我有一个JPA问题:

<named-query name="AUDIT_QUERY">
    <query>
select rx.rxNumber, rx.rxFillStatus.id, tx.rx.rxaaId, tx.id, tx.drugUpc.id, 
tx.compound.id, tx.tpSpecialServiceFee.id,tx.txHistoryDrugUpc.id, 
tx.txHistoryCompound.id, tx.txHistoryTpSpecialServiceFee.id, 
tx.txHistoryRx.id, tx.txNumber,tx.txStatus.id,tx.txAdjudicationStatus.id, 
tx.serviceDate, tx.createDatetime, tx.txQuantity, tx.remainingQuantity, tx.daysSupply, 
tx.ppTotal, tx.tpPaidTotal, tx.adjustedTotal, sig.sigDescriptionStoreLanguage , 
sig.sigDescriptionPatientLanguage , tx.serviceDate
from 
Rx rx JOIN FETCH Tx tx JOIN TxSig sig WHERE rx.rxaaId = tx.rx.rxaaId
and tx.txSig.id = sig.id WHERE 
rx.patient.id = ? 
order by tx.serviceDate desc, tx.txNumber desc,
tx.id desc
    </query>
</named-query>
任何帮助都将不胜感激

谢谢,
Giriraj

要定义连接的条件,使用上的关键字
,而不是其中的
。如果我看对了,你就错了

SELECT
    rx.rxNumber,
    rx.rxFillStatus.id,
    tx.rx.rxaaId,
    tx.id,
    tx.drugUpc.id,
    tx.compound.id,
    tx.tpSpecialServiceFee.id,
    tx.txHistoryDrugUpc.id,
    tx.txHistoryCompound.id,
    tx.txHistoryTpSpecialServiceFee.id,
    tx.txHistoryRx.id,
    tx.txNumber,
    tx.txStatus.id,
    tx.txAdjudicationStatus.id,
    tx.serviceDate,
    tx.createDatetime,
    tx.txQuantity,
    tx.remainingQuantity,
    tx.daysSupply,
    tx.ppTotal,
    tx.tpPaidTotal,
    tx.adjustedTotal,
    sig.sigDescriptionStoreLanguage,
    sig.sigDescriptionPatientLanguage,
    tx.serviceDate
FROM
    Rx rx
JOIN
FETCH
    Tx tx
JOIN
    TxSig sig
ON
    rx.rxaaId = tx.rx.rxaaId
AND tx.txSig.id = sig.id
WHERE
    rx.patient.id = ?
ORDER BY
    tx.serviceDate DESC,
    tx.txNumber DESC,
    tx.id DESC

谢谢你的回复。但是JPA2.0使用WHERE代替ON。JPA 2.1草案中提出了关于的建议。@user1752663您有这方面的来源吗?我很难相信这一点。如果是这样的话,与选择的自然结合是不可能的。您将只有一个
,其中
,并且无法判断这是加入条件还是选择。
SELECT
    rx.rxNumber,
    rx.rxFillStatus.id,
    tx.rx.rxaaId,
    tx.id,
    tx.drugUpc.id,
    tx.compound.id,
    tx.tpSpecialServiceFee.id,
    tx.txHistoryDrugUpc.id,
    tx.txHistoryCompound.id,
    tx.txHistoryTpSpecialServiceFee.id,
    tx.txHistoryRx.id,
    tx.txNumber,
    tx.txStatus.id,
    tx.txAdjudicationStatus.id,
    tx.serviceDate,
    tx.createDatetime,
    tx.txQuantity,
    tx.remainingQuantity,
    tx.daysSupply,
    tx.ppTotal,
    tx.tpPaidTotal,
    tx.adjustedTotal,
    sig.sigDescriptionStoreLanguage,
    sig.sigDescriptionPatientLanguage,
    tx.serviceDate
FROM
    Rx rx
JOIN
FETCH
    Tx tx
JOIN
    TxSig sig
ON
    rx.rxaaId = tx.rx.rxaaId
AND tx.txSig.id = sig.id
WHERE
    rx.patient.id = ?
ORDER BY
    tx.serviceDate DESC,
    tx.txNumber DESC,
    tx.id DESC