JPQL多个JOIN查询

时间:2014-10-22 07:48:27

标签: java oracle jpa hql jpql

有人能帮助我吗? 我得到了那个SQL查询,需要在JPQL中表示,但是我遇到了正确加入的问题:

SELECT alrt.* 
FROM 
 REACTION.ALERT alrt, REACTION.INVESTIGATION inv, 
 REACTION.CLASSIFICATION_TYPE clst, REACTION.FRAUD_TYPE frt, 
 REACTION.TRANS trns, REACTION.CARD crd  
WHERE
  alrt.ISS_INST IN(1201, 1101) AND 
  alrt.MODULE_TYPE = 0 AND 
  0 < (SELECT  COUNT(*) FROM REACTION.INVESTIGATION WHERE REACTION.INVESTIGATION.ALERT_ID = alrt.ID) AND 
  inv.CLASSIFICATION_TYPE_ID IS NOT NULL AND 
  clst.CLASSIFICATION_TYPE = 10 AND 
  (alrt.REMINDER_USER_LOGIN = 'qwr' OR alrt.REMINDER_USER_LOGIN IS NULL) AND 
  alrt.ID = inv.ALERT_ID AND 
  alrt.TRANSACTION_ID = trns.ID(+) AND inv.CLASSIFICATION_TYPE_ID = 
  clst.ID AND inv.FRAUD_TYPE_ID = frt.ID(+) AND trns.HPAN = crd.HPAN(+);

阅读完教程和文档后,我创建了该JPQL查询:

SELECT alrt
    FROM INVESTIGATION inv
        JOIN inv.CLASSIFICATION_TYPE_ID clst
        RIGHT JOIN inv.FRAUD_TYPE_ID frt
        JOIN inv.alert_id alrt
        RIGHT JOIN alrt.transactio_id trns
        RIGHT JOIN trns.HPAN crd
    WHERE
        alrt.ISS_INST IN(1201, 1101) AND
        alrt.MODULE_TYPE = 0 AND 0 < (SELECT COUNT(inv1) FROM INVESTIGATION inv1 WHERE  inv1.ALERT_ID = alrt.ID) AND
        inv.CLASSIFICATION_TYPE_ID IS NOT NULL AND
        clst.CLASSIFICATION_TYPE = 2 AND
       (alrt.REMINDER_USER_LOGIN =  'qwr' OR alrt.REMINDER_USER_LOGIN IS NULL);

但是我得到了错误然后尝试执行它。有人可以告诉我做错了吗? 如果有意义我使用JPA 1.0版本

1 个答案:

答案 0 :(得分:0)

您的错误是加入ID,但不是OR映射对象。 试试这个:

JOIN inv.CLASSIFICATIONTYPE(your mapping property name) clst

如果你没有实体之间的映射关系,你最好用户加入表i.o. OR映射。 阅读JPQL

的更多信息