nested exception is org.hibernate.MappingException: Unknown entity,问题解决

来源:互联网 发布:微信 换手机 数据迁移 编辑:程序博客网 时间:2024/06/01 23:24

今天遇到了nested exception is org.hibernate.MappingException: Unknown entity的问题,在网上查了方法好多,都和我的不一样。

 

问题描述如下:

1、我用spring+hibernate,程序在本机myeclipse访问本地mysql没有问题。

2、我在本机把数据库连接改为informix的可以访问,也可以写库。

3、我把代码部署到linux服务器上,访问informix数据库,出现nested exception is org.hibernate.MappingException: Unknown entity这个错误。

 

解决:

原来我的pojo访问配置为

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

                <property name="packagesToScan">
                        <list>
                                <value>com.xx.xx.pojo</value>
                        </list>
                </property>
                <property name="hibernateProperties">
                        <props>
                                <prop key="hibernate.dialect">
                                        ${hibernate.dialect}
                                </prop>
                                <prop key="hibernate.show_sql">
                                        ${hibernate.show_sql}
                                </prop>
                          </props>
                </property>
                <property name="entityInterceptor">
                        <ref local="trimInterceptor" />
                </property>

        </bean>

 

改为:

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

                <property name="annotatedClasses">
                        <list>
                                <value>com.xx.xx.pojo.Address</value>

                        </list>
                </property>
                <property name="hibernateProperties">
                        <props>
                                <prop key="hibernate.dialect">
                                        ${hibernate.dialect}
                                </prop>
                                <prop key="hibernate.show_sql">
                                        ${hibernate.show_sql}
                                </prop>
                        </props>
                </property>
                <property name="entityInterceptor">
                        <ref local="trimInterceptor" />
                </property>

        </bean>

对红色部分进行了替换,如果有多个pojo类,就可以在list下面添加多个value标签~

原创粉丝点击