春季休眠

发布于 2024-11-09 04:01:07 字数 2016 浏览 0 评论 0原文

我收到此错误:

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>

I'm getting this error:

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

However everything looks to be properly configured. Can anyone see if there is something I'm missing?

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小伙你站住 2024-11-16 04:01:07

您可能缺少@Entity

@Entity
@Table(name="COURSES")
public class Application{
  //some code
}

You might be missing @Entity

@Entity
@Table(name="COURSES")
public class Application{
  //some code
}
暮色兮凉城 2024-11-16 04:01:07

我发现这个错误有两个原因。首先,如果您错过了 Application 类中的 @Entity 。第二个是 Application 类不在构建路径中并且未部署到 JBoss。

I see two reasons for this error. First if you missed the @Entity in Application class. The second one is if the Application class is not in build path and doesn't get deployed to JBoss.

从来不烧饼 2024-11-16 04:01:07

您使用 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>

Are you using JPA or just straight Hibernate? If you're using JPA try defining a META-INF/persistence.xml where you'll define your annotated entity classes:

<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>
╰◇生如夏花灿烂 2024-11-16 04:01:07

您可以尝试通过为其 packagesToScan 属性提供值,让 AnnotationSessionFactoryBean 找到 @Entity 类本身(通过类路径扫描)使用 annotatedClasses 属性手动指定类。

You could try to let the AnnotationSessionFactoryBean find the @Entity classes itself (by classpath scanning), by providing a value for it's packagesToScan property, instead of manually specifying the classes with the annotatedClasses property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文