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>
分享到:
相关推荐
struts2+spring2+hibernate3 Annotation整合例子
Struts2+Spring2+Hibernate3+Annotation所需JAR包
struts2+spring2.5+hibernate3.2 annotation配置完整eclipse项目,带数据库脚本
spring3、 hibernate4 配置声明式事务管理(annotation方式)
使用spring和hibernate的Annotation的小项目,帮助新手理解annotation
JSF+Spring+Hibernate(Annotation)的login小实例,建议入门的朋友看看,老鸟就免了,呵呵。环境:SQLSever2000+jdk5.0+spring2.0+hibernate3.2+jsf
struts2 spring2.5 hibernate3.0 annotation 整合
hibernate annotation spring 中文参考文档
Spring MVC 整合Hibernate的一个小小的用例,适合初学Spring MVC 的学者。
SpringMVC Spring Hibernate 框架整合 Annotation Maven Project
jquery easyUI+struts2+spring+hibernate基于annotation实现的CRM
博文链接:https://liyanboss.iteye.com/blog/183400
spring3,hibernate4 配置声明式事务管理(annotation方式)
超级详细的SSH2项目实例详解,并且附带两个项目详解。两种注解实现方式。...在JavaEE企业级开发中,以SSH2框架为核心的应用非常广,大象根据项目实践经验,通过二个实例,详细的为大家讲解如何实现全注解式的开发。
Spring4 MVC Hibernate4集成,使用Annotation,封装dao层和service层。 环境: spring 4.0.3.RELEASE hibernate 4.3.5.Final mysql 5.1.29
一个小实例工程,说的是spring3+hibernate4配置声明式事务管理(annotation方式)
spring加入hibernate annotation方式第一部分,需要其他部分请查看本人其他资源
Spring3Annotation+Struts2Annotation+Hibernate3Annotation 全注解集成开发,操作Emp表