错误提示1:Caused by: org.hibernate.exception.SQLGrammarException: could not load an entity: [com.qpxnet.entityDAO.Contacts#527]
错误提示2:Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '.200'.我的映射文件 <class name="com.qpxnet.entityDAO.Contacts" table="200_Contacts" schema="dbo" catalog="Restart">
请问这里table="200_Contacts"是不是不能以数字打头?可是我的表不可能再改了,有解决办法吗?如果不是那里错,那又是哪里错了呢?请指出,告诉解决办法,万分感谢。

解决方案 »

  1.   

    你把完整的异常信息贴出啦啊
    先猜测下:
    1. 你的hbm没有配好
    2. 你是不是用HQL查询的,“'.200'”, 200前面有个点,估计是HQL没写好。表名的规范是数据库规定的,Hibernate不会有特殊要求的吧
      

  2.   

     public Contacts findById( java.lang.Integer id) {
            log.debug("getting Contacts instance with id: " + id);
            try {
             System.out.println("@@@@@@@@@@"+id);//打印成功
                Contacts instance = (Contacts) getHibernateTemplate()
                        .get("com.qpxnet.entityDAO.Contacts", id);
          
                System.out.println("************"+id);//打印不成功
                return instance;
            } catch (RuntimeException re) {
                log.error("get failed", re);
                throw re;
            }
        }映射文件:
     <class name="com.qpxnet.entityDAO.Contacts" table="200_Contacts" schema="dbo" catalog="Restart">
            <id name="idContact" type="java.lang.Integer">
                <column name="id_contact" />
                <generator class="native" />
            </id>
            <property name="contType" type="java.lang.Integer">
                <column name="Cont_Type" />
            </property>
    。。
      

  3.   

     getHibernateTemplate() 
                        .get("com.qpxnet.entityDAO.Contacts", id);
    "com.qpxnet.entityDAO.Contacts" -->修改成Contacts.class或者com.qpxnet.entityDAO.Contacts.class
    双引号坚决的不要
      

  4.   

    4楼的朋友,还是不对,你这样改了跟没改一样,结果都是一个错,请问table="200_Contacts"是不是不能以数字打头???
      

  5.   

    SQL语法错误,是200_Contacts这张表的问题.
      

  6.   

    答案:table="200_Contacts"改成table="[200_Contacts]"就行了