我有一个联合查询
SELECT al.C_PERSIST_ID AS id, tkl.C_PERSIST_VERSION AS version, tkl.C_TENANT_ID AS tenantId, tkl.C_MESSAGE AS message, tkl.C_CREATED AS created, tkl.C_INT_STATUS AS statusDB, tkl.C_INT_PRIORITY AS priorityDB,tkl.C_ASSIGNED_PERSON_ID AS assignedPersonId, tkl.C_SOURCE AS name, tkl.C_MAJOR_VERSION AS majorVersion, tkl.C_MINOR_VERSION AS minorVersion, tkl.C_ARCHIVED_FLAG AS archived, tkl.C_DEFINITION_ID AS definitionId,al.C_ALERT_DATETIME AS alertDateTime, al.C_ESCALATION_LEVEL AS escalationLevel, al.C_MAX_ESCALATION_LEVEL AS maxEscalationLevel, al.C_WORKFLOW_TO_START AS workflowToStart al.C_ESCALATED_FLAG AS escalatedDB,al.C_DUEDATE AS dueDate
FROM tkl_Alerts al INNER JOIN tkl_TaskList_Items tkl ON al.C_PERSIST_ID = tkl.C_PERSIST_ID
LEFT JOIN ( SELECT distinct du.C_TASKLISTITEM_ID
FROM tkl_Distribution_Users du
WHERE du.C_USER_ID = '[email protected]' AND du.C_IS_PERSON = 1) X ON tkl.C_PERSIST_ID = X.C_TASKLISTITEM_ID
WHERE tkl.C_ARCHIVED_FLAG = 0
AND tkl.C_INT_STATUS <> 40
AND tkl.C_INT_STATUS <> 50
AND tkl.C_ASSIGNED_PERSON_ID IS NULL
AND X.C_TASKLISTITEM_ID IS NOT NULL
union
SELECT al.C_PERSIST_ID AS id, tkl.C_PERSIST_VERSION AS version, tkl.C_TENANT_ID AS tenantId, tkl.C_MESSAGE AS message, tkl.C_CREATED AS created, tkl.C_INT_STATUS AS statusDB, tkl.C_INT_PRIORITY AS priorityDB,tkl.C_ASSIGNED_PERSON_ID AS assignedPersonId, tkl.C_SOURCE AS name, tkl.C_MAJOR_VERSION AS majorVersion, tkl.C_MINOR_VERSION AS minorVersion, tkl.C_ARCHIVED_FLAG AS archived, tkl.C_DEFINITION_ID AS definitionId,al.C_ALERT_DATETIME AS alertDateTime, al.C_ESCALATION_LEVEL AS escalationLevel, al.C_MAX_ESCALATION_LEVEL AS maxEscalationLevel, al.C_WORKFLOW_TO_START AS workflowToStart, al.C_ESCALATED_FLAG AS escalatedDB,al.C_DUEDATE AS dueDate
FROM tkl_Alerts al INNER JOIN tkl_TaskList_Items tkl ON al.C_PERSIST_ID = tkl.C_PERSIST_ID
WHERE tkl.C_ARCHIVED_FLAG = 0 AND tkl.C_INT_STATUS <> 40 AND tkl.C_INT_STATUS <> 50 AND tkl.C_ASSIGNED_PERSON_ID = '[email protected]'
ORDER BY tkl_Alerts.C_ESCALATION_LEVEL DESC, tkl_Alerts.C_PERSIST_ID DESC
当我将其映射到hbm.xml文件时,出现如下错误:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:277)
at com.infor.ion.process.pulseengine.dao.TaskListItemHeaderDao.lambda$executeItemQuery$45(TaskListItemHeaderDao.java:661)
at com.infor.ion.persist.multitenant.hibernate.Transactional.doInTransaction(Transactional.java:73)
at com.infor.ion.process.pulseengine.dao.TaskListItemHeaderDao.executeItemQuery(TaskListItemHeaderDao.java:655)
at com.infor.ion.process.pulseengine.dao.TaskListItemHeaderDao.getMyAlertHeaders(TaskListItemHeaderDao.java:443)
at com.infor.ion.process.pulseengine.dao.TaskListItemHeaderDao.getMyAlertHeaders(TaskListItemHeaderDao.java:455)
at com.infor.ion.process.pulseengine.logic.TaskListItemHeaderManager$DaoRetry$3.doInRetry(TaskListItemHeaderManager.java:276)
at com.infor.ion.process.common.persist.WithRetry.doInRetry(WithRetry.java:77)
at com.infor.ion.process.common.persist.WithRetry.doInRetry(WithRetry.java:113)
at com.infor.ion.process.pulseengine.logic.TaskListItemHeaderManager$DaoRetry.getMyAlertHeaders(TaskListItemHeaderManager.java:272)
at com.infor.ion.process.pulseengine.logic.TaskListItemHeaderManager.getMyAlertHeaders(TaskListItemHeaderManager.java:78)
at com.infor.ion.process.pulseengine.logic.PulseUIServiceImpl.getMyAlertHeaders(PulseUIServiceImpl.java:149)
at com.infor.ion.process.pulseengine.pulseui.api.services.PulseApiUIProxyService.getMyAlertHeaders(PulseApiUIProxyService.java:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
有任何想法吗?
最佳答案
Hibernate不支持UNION。您可以做的是创建一个视图并基于该视图创建一个Entity类,或者在这种情况下使用本机查询。