为什么" annotatedClasses"如果有@Entity需要的? [英] Why is "annotatedClasses" needed if there is @Entity?
问题描述
您好我建立弹簧Hibernate应用程序。难道我真的从下面需要配置?
<属性名=annotatedClasses>
<列表>
< VALUE> org.fixus.springer.model.User< /值>
< /列表>
< /性>
我已经设置注解驱动的在我的根context.xml中
< MVC:注解驱动/>
<背景:组件扫描基包=org.fixus.springer/>
<背景:组件扫描基包=org.fixus.springer.model/>
现在不应该冬眠全自动采取一切从这个与注释@Entity包并将其转换为表?至于现在没有annotatedClasses他不会从实体创建一个表
的使用docs,卢克!的
[...]例为AnnotationSessionFactoryBean bean定义:
块引用><豆的id =SessionFactory的阶级=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean>
<属性名=数据源REF =数据源/>
<属性名=annotatedClasses>
<列表>
< VALUE> test.package.Foo< /值>
< VALUE> test.package.Bar< /值>
< /列表>
< /性>
< /豆>
或使用类路径扫描实体类的自动检测时:
块引用><豆的id =SessionFactory的阶级=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean>
<属性名=数据源REF =数据源/>
<属性名=packagesToScanVALUE =test.package/>
< /豆>正如你可以看到你定义的所有类明示或仅包扫描之间做出选择。
<背景:组件扫描/>
不承认休眠/ 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!
[...]Example for an AnnotationSessionFactoryBean bean definition:
<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>
Or when using classpath scanning for autodetection of entity classes:
<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.这篇关于为什么&QUOT; annotatedClasses&QUOT;如果有@Entity需要的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!