当我尝试在Java中使用休眠模式运行此查询时,出现了某些错误并引发了
之类的错误。( 12002 ) Internal Service Error. Exception Message : Bad Sql Grammar Exception occurred [Hibernate operation: could not execute query; bad SQL grammar [SELECT COMDT_COM_STAT, COMDT_COM_REFNO, COMDT_COM_CCY
FROM COMDT
WHERE COMDT_COM_REFNO = ?
AND COMDT_COM_RDN BETWEEN ? AND ?
AND COMDT_COM_STAT = ?
GROUP BY COMDT_COM_STAT, COMDT_COM_REFNO, COMDT_COM_CCY
ORDER BY COMDT_COM_REFNO]; nested exception is java.sql.SQLException: Invalid Column Name]
但是当我在PLSQL中使用正确的输入运行相同的查询时,一切都会按我的预期进行。我正在处理此错误2天,但没有任何反应。
谢谢。
<sql-query name="getCommissionBetweenDatesWithStat">
<return alias="xyz"
class="com.ykb.hmn.cms.commission.datamodel.IComDetail"/>
<![CDATA[
SELECT COMDT_COM_CCY AS {xyz.currency}, SUM(xyz.COMDT_COM_AMT1) AS {xyz.amount1}
FROM COMDT
WHERE COMDT_COM_REFNO = :refNo
AND COMDT_COM_RDN BETWEEN :startRdn AND :endRdn
AND COMDT_COM_STAT = :stat
GROUP BY COMDT_COM_STAT, COMDT_COM_REFNO, COMDT_COM_CCY
ORDER BY COMDT_COM_REFNO
]]>
</sql-query>
<class name="com.ykb.hmn.cms.commission.datamodel.IComDetail"
table="COMDT">
<tuplizer class="com.ykb.hmn.inf.core.datamodel.IntfEntityTuplizer"
entity-mode="pojo" />
<id name="oid" type="java.lang.Long">
<column length="17" name="COMDT_ID" />
</id>
<property name="refNo" type="long">
<column length="12" name="COMDT_COM_REFNO" />
</property>
<property name="stat" type="string">
<column length="1" name="COMDT_COM_STAT" />
</property>
<property name="relDay" type="int">
<column length="5" name="COMDT_COM_RDN" />
</property>
<property name="amount1" type="big_decimal">
<column precision="18" scale="2" name="COMDT_COM_AMT1" />
</property>
<property name="currency" type="string">
<column length="4" name="COMDT_COM_CCY" />
</property>
<class/>
COMDT_ID NUMBER(17)
COMDT_COM_REFNO NUMBER(12)
COMDT_COM_AMT1 NUMBER(18,2)
COMDT_COM_STAT VARCHAR2(1)
COMDT_COM_RDN NUMBER(5)
COMDT_COM_CCY VARCHAR2(4)
谢谢。
答案 0 :(得分:0)
我的猜测是,应该使用属性名称而不是列名称声明休眠命名查询。因此,不要在命名查询中使用列名,而应使用属性名。
有关更多详细信息,请参见以下示例:
https://www.journaldev.com/3451/hibernate-named-query-example-namedquery