Spring + Hibernate =未知实体 [英] Spring + Hibernate = Unknown entity
问题描述
org.springframework 我试图将Spring与Hibernate结合使用Annotations, .orm.hibernate3.HibernateSystemException:未知实体:entities.Bar;嵌套异常是org.hibernate.MappingException:未知实体:entities.Bar
这是我的设置.. 。
我的实体:
包实体;
@Entity
public class Bar实现Serializable
{
...
}
我的Bean:
package blah;
@Repository
@Service(fooService)
@RemotingDestination(channels = {my-amf})
public class Foo
{
保护了HibernateTemplate模板;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory)
{
template = new HibernateTemplate(sessionFactory);
@RemotingInclude
public void addBar(String name)throws DataAccessException
{
Bar bar = new Bar();
bar.setName(name);
template.save(bar);
}
}
我在Spring中启用了注释:
< context:annotation-config />
< context:component-scan base-package =blah/>
< bean id =dataSourceclass =org.springframework.jdbc.datasource.DriverManagerDataSource>
< property name =driverClassNamevalue =org.h2.Driver/>
< property name =urlvalue =jdbc:h2:〜/ blahdb / blahdb/>
< / bean>
< bean id =sessionFactoryclass =org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean>
< property name =dataSourceref =dataSource/>
< property name =annotatedClasses>
< list>
< value> entities.Bar< /值>
< / list>
< / property>
< property name =hibernateProperties>
<道具>
< prop key =hibernate.dialect> org.hibernate.dialect.H2Dialect< / prop>
< prop key =hibernate.hbm2ddl.auto>建立< / prop>
< /道具>
< / property>
< / bean>
从Flex应用程序通过BlazeDS调用我的Foo.addBar方法时出现错误。 p>
我真的想避免额外的配置,看来这应该都可以。
我使用Spring 3.0.0.RC1,Hibernate Annotations 3.4.0,Tomcat 6.0.20和Java 1.6.0_15。
有什么想法?谢谢。
尝试使用 import @ javax.persistence.Entity
和不是 org.hibernate.annotations.Entity
用于您的实体
注释。
I'm trying to combine Spring with Hibernate using Annotations and I'm getting the following error:
org.springframework.orm.hibernate3.HibernateSystemException : Unknown entity: entities.Bar; nested exception is org.hibernate.MappingException: Unknown entity: entities.Bar
Here is my setup...
My Entity:
package entities;
@Entity
public class Bar implements Serializable
{
...
}
My Bean:
package blah;
@Repository
@Service("fooService")
@RemotingDestination(channels = { "my-amf" })
public class Foo
{
protected HibernateTemplate template;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory)
{
template = new HibernateTemplate(sessionFactory);
}
@RemotingInclude
public void addBar(String name) throws DataAccessException
{
Bar bar = new Bar();
bar.setName(name);
template.save(bar);
}
}
I'm enabling annotations in Spring:
<context:annotation-config />
<context:component-scan base-package="blah" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:~/blahdb/blahdb" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>entities.Bar</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
I get the error when I call my Foo.addBar method from a Flex application through BlazeDS.
I'd really like to avoid additional configuration and it seems this should all work.
I'm using Spring 3.0.0.RC1, Hibernate Annotations 3.4.0, Tomcat 6.0.20, and Java 1.6.0_15.
Any ideas? Thanks.
Try using import @javax.persistence.Entity
and not org.hibernate.annotations.Entity
for your Entity
annotation.
这篇关于Spring + Hibernate =未知实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!