解决方案 »

  1.   

    你把mappingResources那一段放到hibernateProperties上面试试。
      

  2.   

    试过了还是不行
    严重: Servlet.service() for servlet [default] in context with path [/MyWork] threw exception [org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [from Customer where custname='asd']] with root cause
    org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [from Customer where custname='asd']
      

  3.   

    我以前的项目这样写是好的,你参考一下:<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="mappingResources">
    <list>
    <value>com/ql/entity/User.hbm.xml</value>
    <value>com/ql/entity/Student.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>
    hibernate.show_sql=true
    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    hibernate.cache.use_second_level_cache=true
    hibernate.cache.provider_class=org.hibernate.cache.OSCacheProvider
    hibernate.generate_statistics=true
    hibernate.connection.release_mode=auto
    hibernate.autoReconnect=true
    </value>
    </property>
    </bean>
      

  4.   

    试过了还是不行
    严重: Servlet.service() for servlet [default] in context with path [/MyWork] threw exception [org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [from Customer where custname='asd']] with root cause
    org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [from Customer where custname='asd']
      

  5.   

    路径写全,也许是路径不对,没加载到hbm配置文件。
      

  6.   

    多谢回答,但是还是报同样的错
    以下是我修改后的↓
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
    <property name="mappingResources">
    <list>
    <value>vo/Customer.hbm.xml</value></list>
    </property>
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect
                </value>
                </property>
    </bean>
      

  7.   


    真心求解,虽然用第二种方式可行,
    但是一直身怀一颗打破砂锅问到底的心,况且刚刚接触SSH,对我以后的学习很有用,希望大家发表各自见解,多谢!
      

  8.   

    加上classpath:如下:
    <property name="mappingLocations">
           <list>
             <value>classpath:vo/Customer.hbm.xml</value>
             <value>classpath:vo/Customer.hbm.xml</value>
           </list>
       </property>
      

  9.   


    <property name="mappingLocations">
    <list>
    <value>classpath:/你的路径/你的路径/*.hbm.xml</value>
    </list>
    </property>
    试试通配符方式,匹配你某个文件夹下面的所有以 hbm.xml结尾的文件
      

  10.   

    也试过了↓,还是报同样错误
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect
                </value>
                </property>
            <property name="mappingLocations">
            <list>
                <value>classpath:vo/Customer.hbm.xml</value>
            </list>
         </property>
    </bean>
      

  11.   

    错误还是一样,报没有映射Customer类
    严重: Servlet.service() for servlet [default] in context with path [/MyWork] threw exception [org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [from Customer where custname='zxc']] with root cause
    org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped [from Customer where custname='zxc']
    at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
    at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
    at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
    at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
      

  12.   

    是MyEclipse生成的文件吗?我记得有一个版本它生成映射文件的DTD末尾多了一个空格,所以会出问题!
      

  13.   

    不是用MyEclipse生成的框架,是我手动敲的