问题描述
您好,我正在构建 spring-hibernate 应用程序.我真的需要下面的配置吗?
<value>org.fixus.springer.model.User</value></list></属性>
我在 root-context.xml 中设置了注解驱动
<context:component-scan base-package="org.fixus.springer"/><context:component-scan base-package="org.fixus.springer.model"/>
现在不应该休眠自动从带有注释@Entity 的包中获取所有内容并将其转换为表吗?至于现在没有 annotatedClasses 他不会从实体创建表
使用 文档,卢克!
[...] AnnotationSessionFactoryBean bean 定义示例:
<属性名称=数据源"ref=数据源"/><属性名称="annotatedClasses"><value>test.package.Foo</value><value>test.package.Bar</value></list></属性></bean>
或者当使用类路径扫描来自动检测实体类时:
<属性名称=数据源"ref=数据源"/><property name="packagesToScan" value="test.package"/></bean>
如您所见,您可以选择明确定义所有类或仅定义要扫描的包.<context:component-scan/>
不识别 Hibernate/JPA 注释,因此无效.
Hello I'm building spring-hibernate application. Do i realy need configuration from below ?
<property name="annotatedClasses">
<list>
<value>org.fixus.springer.model.User</value>
</list>
</property>
I've set annotation-driven in my root-context.xml
<mvc:annotation-driven />
<context:component-scan base-package="org.fixus.springer" />
<context:component-scan base-package="org.fixus.springer.model" />
Now shouldn't hibernate automaticly take everything from this packages with annotation @Entity and convert it to table ? As for now without annotatedClasses he won't create a table from a entity
Use the docs, Luke!
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>test.package.Foo</value>
<value>test.package.Bar</value>
</list>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="test.package"/>
</bean>
As you can see you have a choice between defining all classes explicitly or only the package for scanning. <context:component-scan/>
does not recognize Hibernate/JPA annotations and hence has no effect.
这篇关于为什么是“annotatedClasses"?如果有@Entity 需要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!