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>
博客介绍了Hibernate3 Annotation的SessionFactory创建与用mapping resource方式的不同之处,包括Configuration需用新类、使用新的mappingClass元素。还说明了org.springframework.orm.hibernate3.LocalSessionFactoryBean的支持设置,以及专门解决办法org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean的使用及设置示例。
1186

被折叠的 条评论
为什么被折叠?



