无法通过休眠从表中读取数据。但同样的 SQL 在 TOAD 中工作。
SQL:
SELECT distinct pub.asdfg, pub.list, pub.prod, pub.prod_desc FROM Pubsh pub WHERE pub.prod in ('123456')
表定义:
CREATE TABLE "PUBSH"
(
KEY decimal(22) NOT NULL,
PROD varchar2(54) NOT NULL,
PRODKEY decimal(22),
PROD_DESC varchar2(360),
PARTEY decimal(22) NOT NULL,
LIST_TYPE varchar2(90),
PUBLISH_DATE date,
PUBSH_PERIOD varchar2(30) NOT NULL,
PL_KEY decimal(22),
LIST varchar2(750),
EL_KEY decimal(22),
NEL varchar2(60) }
控制台错误:
org.hibernate.SQL - SELECT distinct pub.nel, pub.list, pub.prod, pub.prod_desc FROM PUBSH WHERE pub.prod in ('12345')
org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
org.hibernate.type.StringType - could not read column value from result set; Invalid column name
org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
org.hibernate.util.JDBCExceptionReporter - could not execute query [SELECT distinct pub.nel, pub.list, pub.prodr, pub.desc FROM PUBSH WHERE pub.prod in ('12345')]
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3711)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2806)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:498)
at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.getString(Unknown Source)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
执行 Hibernate 的 DAO 方法:
public List<SearchResult> find(final String Query1) {
return (List<SearchResult>)getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{
Query query1 = session.createSQLQuery(channelQuery1)
.addScalar("nel",Hibernate.STRING)
.addScalar("price",Hibernate.STRING)
.addScalar("prodr",Hibernate.STRING)
.addScalar("prodcr",Hibernate.STRING)
.setResultTransformer(Transformers.aliasToBean(SearchResult.class));
return query1.list();
}
请告知为什么我在通过休眠访问时收到无效的列名错误?