分享

Hibernate Mapping 中的catalog属性导制生成HQL时报错!_~小雨_...

 旭龙 2010-09-22

<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()
查询方法: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 表名上,
这个错误是说没有找到表名:Caused by: java.sql.SQLException: Table 'zhidao.zhidao__zd_question' doesn't exist
其实我数据库里的表名是zd_question但为什么又在前面加上了zhidao__了呢?这个是我数据库的数名啊~!!汗~!
后来发现
<class name="com.zhidao.model.ZdQuestion" table="zd_question" catalog="zhidao">
多了这个~!“catalog="zhidao" ”这个地方是把库名放在上面了,当生成Hibernate生成SQL语句时把表名前又加上了库名,所以报错了~!

下面让我改了,马上就好使了~!汗~!!
<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>


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多