http://blog.csdn.net/flyingfalcon/article/details/8273618
————————————————————————————————————————————————————————
1:
public class AnnotationSessionFactoryBeanextends LocalSessionFactoryBean
Subclass of Spring's standard LocalSessionFactoryBean for Hibernate3, supporting JDK 1.5+ annotation metadata for mappings. Requires the Hibernate3 Annotation add-on to be present.
2:实例代码
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="annotatedClasses"> <list> <value>test.package.Foo</value> <value>test.package.Bar</value> </list> </property> <property name="annotatedPackages"> <list> <value>test.package</value> </list> </property> </bean>
3:实际运用
图:User类
其中类应用了Hibernate和Spring的注解
图:应用中的配置信息
补充:官方文档给出的示例http://static.springsource.org/spring/docs/2.5.6/api/org /springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.html
org.springframework.orm.hibernate3.annotation
Class AnnotationSessionFactoryBean
java.lang.Object
org.springframework.orm.hibernate3.AbstractSessionFactoryBean
org.springframework.orm.hibernate3.LocalSessionFactoryBean
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
- All Implemented Interfaces:
- BeanClassLoaderAware, DisposableBean, FactoryBean, InitializingBean, ResourceLoaderAware, PersistenceExceptionTranslator
public class AnnotationSessionFactoryBeanextends LocalSessionFactoryBeanimplements ResourceLoaderAware
Subclass of Spring's standard LocalSessionFactoryBean for Hibernate, supporting JDK 1.5+ annotation metadata for mappings.
Note: This class requires Hibernate 3.2 or higher, with the Java Persistence API and the Hibernate Annotations add-on present.
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>