Spring3与Hibernate4整合,Spring中配置Hibernate基于XML和annotation的sessionFactory方式。
2013-04-13 21:04
896 查看
在Spring配置文件中创建sessionFactory的bean,其中Hibernate基于XML创建的sessionFactory配置代码如下:
Hibernate基于annotation注解创建的sessionFactory配置代码如下:
<list>
<value> com.syyyy.model.Person </value>
</list>
</property> <!-- 配置Hibernate属性 --> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.format_sql=true; </value> </property> </bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <!-- 依赖注入数据源,注入上文中的mysqldataSource --> <property name="dataSource" ref="mysqldataSource"/> <!-- mappingResources属性用来列出全部映射文件 --> <property name="mappingResources"> <list> <value>com/syyyy/model/Person.hbm.xml</value> </list> </property> <!-- 配置Hibernate属性 --> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.format_sql=true; </value> </property> </bean>
Hibernate基于annotation注解创建的sessionFactory配置代码如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <!-- 依赖注入数据源,注入上文中的mysqldataSource --> <property name="dataSource" ref="mysqldataSource"/> <!-- annotatedClasses属性用来指定全部的映射类 --><property name="annotatedClasses">
<list>
<value> com.syyyy.model.Person </value>
</list>
</property> <!-- 配置Hibernate属性 --> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.hbm2ddl.auto=update hibernate.show_sql=true hibernate.format_sql=true; </value> </property> </bean>
相关文章推荐
- spring与hibernate整合配置基于Annotation注解方式管理实务
- Spring整合Hibernate:1、annotation方式管理SessionFactory
- spring与hibernate整合applicatContext.xml配置,得到sessionFactory
- Spring整合Hibernate:1、annotation方式管理SessionFactory
- Spring整合Hibernate:1、annotation方式管理SessionFactory
- Spring整合Hibernate:1、annotation方式管理SessionFactory
- Spring整合Hibernate管理事务(xml配置方式)
- Spring整合hibernate中Datasouce、SessionFactory、Transaction配置
- spring基于xml加载和读取properties配置文件的方式
- Spring中的AOP(二)——基于Annotation的配置方式(一)
- Spring和Hibernate使用maven整合时pom.xml的配置
- Spring 采用基于XML方式配置事务
- spring aop的使用(注解方式以及基于xml配置方式)
- s2sh整合中hibernate两种配置方式中spring配置文件中的不同
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean(供自己学习)
- Spring中的AOP(三)——基于Annotation的配置方式(二)
- Spring基于XML和annotation的配置
- spring事务配置 :基于AspectJ的XML方式
- Spring 整合hibernate和mybatis的 applicationContext.xml的配置
- Spring整合heibernate在hbm.xml配置出现错误org.hibernate.tuple.entity.PojoEntityTuplizer Caused by: org.hiberna