<hibernate-mapping>
<class name="com.zhidao.model.ZdQuestion" table="zd_question" catalog="zhidao">
<id name="zdId" type="int">
<column name="zd_id" />
<generator class="identity" />
</id>
<property name="zdTitle" type="string">
<column name="zd_title" length="45" not-null="true" />
</property>
<property name="zdContent" type="string">
<column name="zd_content" length="45" not-null="true" />
</property>
<property name="zdTime" type="timestamp">
<column name="zd_time" length="19" not-null="true" />
</property>
<property name="zuId" type="int">
<column name="zu_id" not-null="true" />
</property>
<property name="zdMoney" type="int">
<column name="zd_money" not-null="true" />
</property>
<property name="zdGroup" type="string">
<column name="zd_group" length="45" not-null="true" />
</property>
<property name="zdIsQuestion" type="int">
<column name="zd_isQuestion" not-null="true" />
</property>
<property name="zdIsbest" type="int">
<column name="zd_isbest" not-null="false" />
</property>
</class>
</hibernate-mapping>
報錯:
execute method getDaoImp()
查詢(xún)方法:searchPager():from ZdQuestion a
2007-07-28 13:32:07,906 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2007-07-28 13:32:07,953 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[INFO] SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
Hibernate: select zdquestion0_.zd_id as zd1_, zdquestion0_.zd_title as zd2_1_, zdquestion0_.zd_content as zd3_1_, zdquestion0_.zd_time as zd4_1_, zdquestion0_.zu_id as zu5_1_, zdquestion0_.zd_money as zd6_1_, zdquestion0_.zd_group as zd7_1_, zdquestion0_.zd_isQuestion as zd8_1_, zdquestion0_.zd_isbest as zd9_1_ from zhidao__zd_question zdquestion0_ limit ?
2007-07-28 13:32:08,093 [org.hibernate.util.JDBCExceptionReporter]-[WARN] SQL Error: 1146, SQLState: 42S02
2007-07-28 13:32:08,093 [org.hibernate.util.JDBCExceptionReporter]-[ERROR] Table 'zhidao.zhidao__zd_question' doesn't exist
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:890)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.zhidao.dao.DaoImp.searchPager(DaoImp.java:27)
at com.zhidao.service.ServiceImp.listData(ServiceImp.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy1.listData(Unknown Source)
at com.zhidao.struts.action.AskAaction.simpleSearchAsk(AskAaction.java:88)
at com.zhidao.struts.action.AskAaction.execute(AskAaction.java:56)
Caused by: java.sql.SQLException: Table 'zhidao.zhidao__zd_question' doesn't exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1024)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:75)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 54 more
從上面的錯誤可以看出,錯誤在zhidao.zhidao__zd_question 表名上,
這個(gè)錯誤是說(shuō)沒(méi)有找到表名:Caused by: java.sql.SQLException: Table 'zhidao.zhidao__zd_question' doesn't exist
其實(shí)我數據庫里的表名是zd_question但為什么又在前面加上了zhidao__了呢?這個(gè)是我數據庫的數名啊~??!汗~!
后來(lái)發(fā)現
<class name="com.zhidao.model.ZdQuestion" table="zd_question" catalog="zhidao">
多了這個(gè)~!“catalog="zhidao" ”這個(gè)地方是把庫名放在上面了,當生成Hibernate生成SQL語(yǔ)句時(shí)把表名前又加上了庫名,所以報錯了~!
下面讓我改了,馬上就好使了~!汗~??!
<hibernate-mapping package="com.zhidao.model">
<class name="ZdQuestion" table="zd_question">
<id name="id" type="int">
<column name="id" />
<generator class="identity" />
</id>
<property name="zdTitle" type="string">
<column name="zd_title" length="45" not-null="true" />
</property>
<property name="zdContent" type="string">
<column name="zd_content" length="45" not-null="true" />
</property>
<property name="zdTime" type="timestamp">
<column name="zd_time" length="19" not-null="true" />
</property>
<property name="zuId" type="int">
<column name="zu_id" not-null="true" />
</property>
<property name="zdMoney" type="int">
<column name="zd_money" not-null="true" />
</property>
<property name="zdGroup" type="string">
<column name="zd_group" length="45" not-null="true" />
</property>
<property name="zdIsQuestion" type="int">
<column name="zd_isQuestion" not-null="true" />
</property>
<property name="zdIsbest" type="int">
<column name="zd_isbest" not-null="false" />
</property>
</class>
</hibernate-mapping>
聯(lián)系客服