我需要select ST_AsText(column_name)
使用hibernate从表执行createSQlQuery()
。
当我执行该查询时,它表明在结果集中找不到列名。
但是,当我在PGAdmin浏览器中执行相同的查询时,该查询有效。
Query query = session.createSQLQuery("select ST_AsText(END2536) from country where object='something'");
((SQLQuery) query).addScalar(column, Hibernate.STRING);
String geomValue = (String) query.uniqueResult();
query.setCacheable(true);
query.setCacheRegion("query.CommonManagement");
错误讯息:
16:56:27,076 INFO [org.hibernate.type.StringType] (http--172.20.211.235-8080-1) could not read column value from result set: END2536; The column name END2536 was not found in this ResultSet.
16:56:27,077 WARN [org.hibernate.util.JDBCExceptionReporter] (http--172.20.211.235-8080-1) SQL Error: 0, SQLState: 42703
16:56:27,077 ERROR [org.hibernate.util.JDBCExceptionReporter] (http--172.20.211.235-8080-1) The column name END2536 was not found in this ResultSet.
16:56:27,080 ERROR [stderr] (http--172.20.211.235-8080-1) org.hibernate.exception.SQLGrammarException: could not execute query
我在这里想念什么?
谢谢大家,我知道了问题所在。这是因为结果集具有别名,并且我启用了查询缓存。因此,列名(END2536)不在结果集中。当我评论查询缓存部分时,它工作正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句