我收到此错误:

org.hibernate.MappingException: Unknown entity: xxx.model.Application


但是,所有内容似乎都已正确配置。谁能看到我想念的东西吗?



<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="file:/dctm/db.props"/>
</bean>

<bean id="xxxDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="${db.url}"/>
    <property name="username" value="${db.username}"/>
    <property name="password" value="${db.password}"/>
</bean>

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

    <property name="annotatedClasses">
    <list>
        <value>xxx.model.Application</value>
    </list>
        </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${db.dialect}</prop>
            <prop key="hibernate.show_sql">${db.debug_sql}</prop>
            <prop key="hibernate.c3p0.minPoolSize">1</prop>
            <prop key="hibernate.c3p0.maxPoolSize">5</prop>
            <prop key="hibernate.c3p0.timeout">${db.timeout}</prop>
            <prop key="hibernate.c3p0.max_statement">50</prop>
            <prop key="hibernate.c3p0.testConnectionOnCheckout">false</prop>
            <prop key="hibernate.current_session_context_class">thread</prop>
        </props>
    </property>
</bean>

<bean id="patiDao" class="xxx.dao.hibernate.PatiHibernateDao">
    <property name="sessionFactory" ref="xxxSessionFactory"/>
</bean>

最佳答案

您是使用JPA还是直接使用Hibernate?如果您使用的是JPA,请尝试定义一个META-INF / persistence.xml,在其中定义带注释的实体类:

<persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>java:/MyDS</non-jta-data-source>
    <class>xxx.model.Application</class>
    <class>xxx.model.Class2</class>
    <exclude-unlisted-classes />
</persistence-unit>

09-30 18:56
查看更多