添加的时候没有报错 但是查询的时候报这个错误 org.springframework.orm.hibernate3.HibernateQueryException: lxNews is not mapped [from lxNews]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: lxNews is not mapped [from lxNews]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:921)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)
at com.news.dao.impl.NewsDaoImpl.selectNewsCount(NewsDaoImpl.java:137)
at com.news.service.impl.NewsServicesImpl.selectNewsCount(NewsServicesImpl.java:61)
at com.news.service.impl.NewsServicesImpl$$FastClassByCGLIB$$9082df78.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

解决方案 »

  1.   

    applicationContext。xml 文件<?xml version="1.0" encoding="UTF-8"?>
    <beans 
        xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver">
      </property>
      <property name="url" value="jdbc:mysql://localhost:3306/news">
      </property>
      <property name="username" value="root">
      </property>
      <property name="password" value="lx">
      </property>
    </bean>
    <bean id="sessionFactory" 
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
       <ref bean="dataSource" />
      </property>
        <property name="hibernateProperties">
         <props>
         <prop key="hibernate.dialect">
         org.hibernate.dialect.MySQLDialect
         </prop>
         <prop key="shou_sql">true</prop>
         </props>
        </property>
        <property name="mappingResources">
         <list>
         <value>com/news/model/News.xml</value>
         </list>
        </property>  
    </bean>



    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory">
    </property>
    </bean>

    <tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
    <tx:method name="get*" read-only="true"/>
    <tx:method name="find*" read-only="true"/>
    <tx:method name="search*" read-only="true"/>
    <tx:method name="query*" read-only="true"/>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="del*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="do*" propagation="REQUIRED"/>
    <tx:method name="*" propagation="REQUIRED" read-only="true"/>
    </tx:attributes>
    </tx:advice>
    <aop:config proxy-target-class="true">
    <aop:pointcut expression="execution(* com.news.service..*.*(..))" id="serviceMethod"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
    </aop:config>
    </beans>
      

  2.   

    lxNews is not mapped [from lxNews]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: lxNews is not mapped [from lxNews]
      

  3.   

     nested exception is org.hibernate.hql.ast.QuerySyntaxException: lxNews is not mapped [from lxNews]
    lxNews 这是你要查询的类名? 如果是类的话,要与类名相同,应该首字母大写“LxNews”楼主试试,如果还不行的话把查询方法贴出来看看