这是我正在尝试使用的较大查询的较小版本。当我运行查询时,我收到以下错误。我已经尝试尽可能多地删除查询以尝试找到有罪的列,但没有任何成功。我正在使用 Spring 3.2.1、Hibernate 3.6 和 Oracle 11g
Caused by: java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3711)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2763)
at oracle.jdbc.driver.OracleResultSet.getBigDecimal(OracleResultSet.java:368)
at org.hibernate.type.descriptor.sql.DecimalTypeDescriptor$2.doExtract(DecimalTypeDescriptor.java:62)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
询问:
String query = "SELECT d.ID as {d.id}, d.DETAIL_ORDER as {d.detailOrder}, g.ID as {g.id}, g.NAME as {g.name} " +
"FROM EVAL_MASTER_EVAL_DETAIL d " +
"JOIN EVAL_QUESTION_GROUP g ON d.GROUP_ID = g.ID " +
"WHERE d.ACTIVE = 'Y' " +
"AND d.MASTER_EVAL_ID = :evalId" +
" ORDER BY d.DETAIL_ORDER ASC";
details = session.createSQLQuery(query).addEntity("d", EvalMasterEvalDetail.class)
.addEntity("g", EvalQuestionGroup.class).setParameter("evalId", evalId).list();
产生的休眠查询:
Hibernate: SELECT d.ID as ID29_0_, d.DETAIL_ORDER as DETAIL5_29_0_, g.ID as ID34_1_, g.NAME as NAME34_1_ FROM EVAL_MASTER_EVAL_DETAIL d JOIN EVAL_QUESTION_GROUP g ON d.GROUP_ID = g.ID WHERE d.ACTIVE = 'Y' AND d.MASTER_EVAL_ID = ? ORDER BY d.DETAIL_ORDER ASC
映射(用于验证名称)
<hibernate-mapping>
<class name="org.anes.surveys.domain.EvalMasterEvalDetail" table="EVAL_MASTER_EVAL_DETAIL">
<id name="id" type="big_decimal">
<column name="ID" precision="22" scale="0" />
<generator class="sequence-identity" >
<param name="sequence">EVAL_MASTER_EVAL_DETAIL_SEQ</param>
</generator>
</id>
<many-to-one name="evalQuestionGroup" class="org.anes.surveys.domain.EvalQuestionGroup" fetch="select">
<column name="GROUP_ID" precision="22" scale="0" />
</many-to-one>
<many-to-one name="evalMasterEvaluation" class="org.anes.surveys.domain.EvalMasterEvaluation" fetch="select">
<column name="MASTER_EVAL_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<property name="detailOrder" type="big_decimal">
<column name="DETAIL_ORDER" precision="22" scale="0" not-null="true" />
</property>
<property name="active" type="string">
<column name="ACTIVE" length="1" not-null="true" />
</property>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.anes.surveys.domain.EvalQuestionGroup" table="EVAL_QUESTION_GROUP">
<id name="id" type="big_decimal">
<column name="ID" precision="22" scale="0" />
<generator class="sequence-identity" >
<param name="sequence">EVAL_QUESTION_GROUP_SEQ</param>
</generator>
</id>
<property name="name" type="string">
<column name="NAME" not-null="true" />
</property>
<set name="evalMasterEvalDetails" table="EVAL_MASTER_EVAL_DETAIL" inverse="true" lazy="true" fetch="select">
<key>
<column name="GROUP_ID" precision="22" scale="0" />
</key>
<one-to-many class="org.anes.surveys.domain.EvalMasterEvalDetail" />
</set>
</class>
</hibernate-mapping>
编辑:尝试了以下,仍然得到无效的列错误。ACTIVE & d.active 是字符串。
String query = "SELECT ACTIVE as {d.active} " +
"FROM EVAL_MASTER_EVAL_DETAIL";
details = session.createSQLQuery(query).addEntity("d", EvalMasterEvalDetail.class).list();
String query = "SELECT d.ID " +
"FROM EVAL_MASTER_EVAL_DETAIL d ";
details = session.createSQLQuery(query).addEntity("d", EvalMasterEvalDetail.class).list();
String query = "SELECT ID " +
"FROM EVAL_MASTER_EVAL_DETAIL";
details = session.createSQLQuery(query).addEntity("d", EvalMasterEvalDetail.class).list();
这有效,但我只得到标量值:
String query = "SELECT ID " +
"FROM EVAL_MASTER_EVAL_DETAIL";
details = session.createSQLQuery(query).list();