春季休眠
我收到此错误:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能缺少
@Entity
You might be missing
@Entity
我发现这个错误有两个原因。首先,如果您错过了
Application
类中的@Entity
。第二个是Application
类不在构建路径中并且未部署到 JBoss。I see two reasons for this error. First if you missed the
@Entity
inApplication
class. The second one is if theApplication
class is not in build path and doesn't get deployed to JBoss.您使用 JPA 还是直接使用 Hibernate?如果您使用 JPA,请尝试定义 META-INF/persistence.xml,您将在其中定义带注释的实体类:
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:
您可以尝试通过为其 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.