org.hibernate.MappingException: Unknown entity

ssh项目运行一直报org.hibernate.MappingException: Unknown entity 。网络上有很多其他的关于这个问题的解决方法,我这里记录的是我在撸码过程中遇到的情形。
spring-xxx.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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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">


        <import resource="classpath:**/config/datasource_amicos_dev.xml" />
        <import resource="classpath:**/config/datasource_foc.xml" />

    <bean id="medetHRSessionFactory2"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="prodszaDataSource" />
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.Oracle9Dialect
                </prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">
                    true
                </prop>
                <prop key="hibernate.cache.provider_class">
                    org.hibernate.cache.EhCacheProvider
                </prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.connection.release_mode">
                    auto
                </prop>
                <prop key="hibernate.autoReconnect">true</prop>
                <prop key="hibernate.generate_statistics">true</prop>


            </props>
        </property>
         <property name="packagesToScan">
            <list>                 <value>com/sXxx/smart/productlogXXX/model/</value> 
            </list>
        </property> 

    </bean>

    <!-- *************Transaction manager for a single Hibernate SessionFactory (alternative to JTA)************ -->

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

    <tx:advice id="txAdvice"
        transaction-manager="medetHRTransactionManager2">
        <tx:attributes>
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>

    <aop:config proxy-target-class="true">
        <aop:advisor
            pointcut="execution(* com.szair.smartme.productlogsys.*.*.*(..))"
            advice-ref="txAdvice" />
    </aop:config>


    <!-- 用@Transactional注释的方式控制事务 -->
    <tx:annotation-driven
        transaction-manager="medetHRTransactionManager2"
        proxy-target-class="true" />



    <!-- 使Spring关注Annotation -->
    <context:annotation-config />



    <!-- 让Spring通过自动扫描来查询和管理Bean -->
    <context:component-scan base-package="com.szair.smartme.productlogsys" />

    <!-- 配置Quartz -->
    <bean id="quartzJob" class="com.szair.smartme.productlogsys.service.QuartzJob"></bean>

    <bean id="quartzJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 指定任务类 -->
        <property name="targetObject" ref="quartzJob"></property>
        <!-- 指定执行的方法 -->
        <property name="targetMethod" value="execute"></property>
    </bean>

    <bean id="quartzJobTrigger"
        class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="quartzJobDetail" />
        <!-- 每10秒运行一次 -->
        <property name="cronExpression" value="0/30 * * * * ?" />
    </bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="quartzJobTrigger" />
            </list>
        </property>
    </bean>

</beans>

自认为是没有什么错的,但是就是提示unknow entity 的错误。后来才明白错误出在哪了。因为这个项目里有两个spring的配置文件,我是直接在前人写好的dao里接着写,然而那个dao里引用的是datasource和我在建表的数据库不一致,所以才出现这个问题。后来就自己新建了一个dao类,里面引用正确的sessionFactory就可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值