我有多个Spring配置文件公共的配置文件添加Hibernate的映射文件
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
destroy-method="destroy">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
</props>
</property>
<!-- mappingLocations属性用来列出指定路经的全部映射文件 -->
<property name="mappingLocations">
   <value>cn\jboa\entity\*.hbm.xml</value>
</property>
</bean>这是它报的错
org.springframework.orm.hibernate3.HibernateQueryException: SysEmployee is not mapped [from SysEmployee as s where s.sn=?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: SysEmployee is not mapped [from SysEmployee as s where s.sn=?]
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)org.hibernate.hql.ast.QuerySyntaxException: SysEmployee is not mapped [from SysEmployee as s where s.sn=?]这是我写的JUnit并测试通过 
private static SysEmployeeDao sysEmployeeDao;
@AfterClass
public static void testDownAfterClass() throws Exception {
SysEmployee sysEmployee = new SysEmployee();
sysEmployee.setSn("100001");
sysEmployee.setPassword("123");
System.out.println(sysEmployeeDao.login(sysEmployee));
} @Before
public void setUp() throws Exception {
String[] string = {"applicationContext.xml","jBOASpringContext1.xml"};
ApplicationContext context = new ClassPathXmlApplicationContext(string);
sysEmployeeDao = (SysEmployeeDao)context.getBean("sysEmployeeDao");
}
它能通过是不是也就说明Spring可以通过mappingLocations <value>cn\jboa\entity\*.hbm.xml</value> 找见对应的映射文件

解决方案 »

  1.   

    这个是我的原配置文件!
    <?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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-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/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop">
    <!-- 与Hibernate整合 -->
    <bean id="config"
    class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:jdbc.properties</value>
    </list>
    </property>
    </bean>
    <!-- 将bean交由spring管理可以 用<bean></bean>和扫描加注 -->
    <!-- 扫描该包及该包下的子包  -->
    <context:component-scan base-package="com.yss"></context:component-scan>
    <!-- 集成hibernate  sessionFactory单例模式  线程安全  创建耗内存-->

    <!-- 将hibernate的事务也交由spring管理 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="${mysql.jdbc.driver}" />
    <property name="jdbcUrl" value="${mysql.jdbc.url}" />
    <property name="user" value="${mysql.jdbc.user}" />
    <property name="password" value="${mysql.jdbc.password}" />
    <!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
    <property name="initialPoolSize" value="${mysql.jdbc.initialPoolSize}" />
    <!--连接池中保留的最小连接数。-->
    <property name="minPoolSize" value="${mysql.jdbc.minPoolSize}" />
    <!--连接池中保留的最大连接数。Default: 15 -->
    <property name="maxPoolSize" value="${mysql.jdbc.maxPoolSize}" />
    <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
    <property name="maxIdleTime" value="${mysql.jdbc.maxIdleTime}" />
    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
    <property name="acquireIncrement" value="${mysql.jdbc.acquireIncrement}" />
    <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
    <property name="idleConnectionTestPeriod" value="${mysql.jdbc.idleConnectionTestPeriod}" />
    </bean> <!-- 配置sessionFactory -->
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
    destroy-method="destroy">
    <property name="dataSource">
    <ref local="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="show_sql">true</prop>
    </props>
    </property>
    <!-- mappingLocations属性用来列出指定路经的全部映射文件 -->
    <property name="mappingLocations">
    <value>cn/jboa/entity/*.hbm.xml</value>
    </property>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="txManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!-- 配置事务通知(指定事务管理器) -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
    <!-- 定义属性,声明事务规则 -->
    <tx:attributes>
    <!-- 对get/find/search/query开头的方法要求只读事务 -->
    <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="upd*" propagation="REQUIRED" />
    <tx:method name="do*" propagation="REQUIRED" />
    <tx:method name="*" propagation="REQUIRED" read-only="true" />
    </tx:attributes>
    </tx:advice>
    <!-- 为需要进行事务管理的方法创建serviceMethod切入点 -->
    <aop:config>
    <!-- 定义哪些方法应用这些规则 -->
    <!-- 第一个*代表所有的返回值类型,第二个*代表所有的类,第三个*代表类所有的方法,最后的..代表所有的参数 -->
    <aop:pointcut id="serviceMethod"
    expression="execution(* cn.jboa.dao.impl.*.*(..))" />
    <!-- 将事务通知与应用规则的方法组合 -->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
    </aop:config>
    </beans>这个是个成功的配置文件!过去很久了,我也忘记结贴了!你参考一下吧!