您的位置:首页 > 编程语言 > Java开发

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类的说明
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: