在hibernate+mysql的环境下,执行select * from Aa12 su不会出错,但是select count(*) from (select * from Aa12 su) a时会出错。请大家给些意见建议。谢谢
===========================================
Hibernate: select count(*) from (select * from Aa12 su) a
INFO : 2007-11-23 13:22:09,404: NullableType[line:132}: could not read column value from result set: ; Column '' not found.
WARN : 2007-11-23 13:22:09,404: JDBCExceptionReporter[line:71}: SQL Error: 0, SQLState: S0022
ERROR: 2007-11-23 13:22:09,404: JDBCExceptionReporter[line:72}: Column '' not found.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at com.lbs.apps.query.Test.main(Test.java:24)
Caused by: java.sql.SQLException: Column '' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
at com.mysql.jdbc.ResultSet.getBigDecimal(ResultSet.java:1226)
at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:34)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)
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:594)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
... 7 more
===========================================
Hibernate: select count(*) from (select * from Aa12 su) a
INFO : 2007-11-23 13:22:09,404: NullableType[line:132}: could not read column value from result set: ; Column '' not found.
WARN : 2007-11-23 13:22:09,404: JDBCExceptionReporter[line:71}: SQL Error: 0, SQLState: S0022
ERROR: 2007-11-23 13:22:09,404: JDBCExceptionReporter[line:72}: Column '' not found.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at com.lbs.apps.query.Test.main(Test.java:24)
Caused by: java.sql.SQLException: Column '' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
at com.mysql.jdbc.ResultSet.getBigDecimal(ResultSet.java:1226)
at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:34)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:139)
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:594)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
... 7 more
实体都是用工具自动生成的,应该不会有错,而上边这个简单的语句也不应该有错的阿
我用的数据库是mysql,但是在oracle上策就没有问题。
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.*.*.entity.Aa12" table="aa12" catalog="commodities">
<id name="aaa020" type="java.lang.String">
<column name="aaa020" />
<generator class="uuid.hex" />
</id>
<property name="aaa021" type="java.lang.String">
<column name="aaa021" length="60" />
</property>
</class>
</hibernate-mapping>======================================
/**
* Aa12 generated by MyEclipse Persistence Tools
*/public class Aa12 implements java.io.Serializable {
// Fields private String aaa020;
private String aaa021;
// Constructors /** default constructor */
public Aa12() {
}
/** full constructor */
public Aa12(String aaa021) {
this.aaa021 = aaa021;
}
// Property accessors public String getAaa020() {
return this.aaa020;
}
public void setAaa020(String aaa020) {
this.aaa020 = aaa020;
} public String getAaa021() {
return this.aaa021;
}
public void setAaa021(String aaa021) {
this.aaa021 = aaa021;
}
}
INFO org.hibernate.type.BigIntegerType - could not read column value from result set: ; Column '' not found.
select
distinct roleid ,
count(roleid) as logcount,
FROM_UNIXTIME(time,
'%Y-%m-%d') as days
from
tunshi_log_login
where
serverGroupId = '1'
and islogin = 1
group by
days,
roleid
having
days = FROM_UNIXTIME(1330601944,'%Y-%m-%d')