Spring中使用Hibernate3的Annotation
2005-08-07 18:23
357 查看
Hibernate3 Annotation的SessionFactory创建需要有两个地方与用mapping resource的方式不同:
Configuration需要使用新的org.hibernate.cfg.AnnotationConfiguration
需要使用新的mappingClass元素而不是使用mappingResource
org.springframework.orm.hibernate3.LocalSessionFactoryBean 对此的支持是configurationClass属性及configLocation属性,也就是分别设置configurationClass和hibernate.cfg.xml的位置(mappingClass在配置文件中设置)。
设置的例子如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean是专门针对这个问题的解决办法,只需要使用这个类做SessionFactory,则只需要直接设置annotatedClasses属性即可。设置的例子如下:
<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>
</bean>
请参见:AnnotationSessionFactoryBean类的说明
Configuration需要使用新的org.hibernate.cfg.AnnotationConfiguration
需要使用新的mappingClass元素而不是使用mappingResource
org.springframework.orm.hibernate3.LocalSessionFactoryBean 对此的支持是configurationClass属性及configLocation属性,也就是分别设置configurationClass和hibernate.cfg.xml的位置(mappingClass在配置文件中设置)。
设置的例子如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean是专门针对这个问题的解决办法,只需要使用这个类做SessionFactory,则只需要直接设置annotatedClasses属性即可。设置的例子如下:
<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>
</bean>
请参见:AnnotationSessionFactoryBean类的说明
相关文章推荐
- 使用Annotation编写Entity减少Spring,hibernate配置。
- Spring中使用Hibernate3的Annotation
- Hibernate注解(Annotation)使用以及Spring整合
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理
- 使用Spring 2.5 和 Hibernate 3.2 开发MVC Web程序(基于annotation特性)
- 使用Spring 2.5 和 Hibernate 3.2 开发MVC Web程序(基于annotation特性)
- 使用Annotation编写Entity减少Spring,hibernate配置
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理
- spring_Spring+Hibernate_使用Annotation进行声明式事务管理
- 使用Spring 2.5 和 Hibernate 3.2 开发MVC Web程序(基于annotation特性)
- hibernate3.5和spring结合使用annotation时onetomany的bug
- Spring整合Hibernate:2、使用Annotation方式进行声明式的事务管理
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- 使用Annotation编写Entity减少Spring,hibernate配置。
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- 使用Spring 2.5 和 Hibernate 3.2 开发MVC Web程序(基于annotation特性)
- hibernate--annotation的使用
- 使用Maven整合Spring+SpringMVC+Hibernate
- 使用struts+spring+hibernate组装你的web应用架构