spring中整合hibernate
来源:互联网 发布:js数组移除元素 编辑:程序博客网 时间:2024/05/24 06:08
1.不用dataSource引入hibernate.cfg.xml
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="configLocation">
- <value>classpath:hibernate.cfg.xml</value>
- </property>
- </bean>
2.丢掉hibernate.cfg.xml
1>使用注解:
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="<span style="background-color: #ff0000;">annotatedClasses</span>">
- <list>
- <value>com.bjsxt.model.User</value>
- <value>com.bjsxt.model.Log</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">
- org.hibernate.dialect.MySQLDialect
- </prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- </bean>
2>不使用注解
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <!-- 依赖注入数据源,注入正是上面定义的dataSource -->
- <property name="dataSource" ref="dataSource" />
- <property name="<span style="background-color: #ff0000;">mappingResources</span>"><!-- mappingResouces属性用来列出全部映射文件 -->
- <list><!-- 以下用来列出Hibernate映射文件 -->
- <value>jsf/web/entity/User.hbm.xml</value>
- </list>
- </property>
- <!-- 定义Hibernate的SessionFactory的属性 -->
- <property name="hibernateProperties">
- <props>
- <!-- 指定数据库方言 -->
- <prop key="hibernate.dialect">
- org.hibernate.dialect.MySQLInnoDBDialect</prop>
- <!-- 是否根据需要每次自动创建数据库 -->
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- <!-- 显示Hibernate持久化操作所生成的SQL -->
- <prop key="hibernate.show_sql">true</prop>
- <!-- 将SQL脚本进行格式化后再输出 -->
- <prop key="hibernate.format_sql">true</prop>
- </props>
- </property>
- </bean>
3>使用packagesToScan
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="<span style="background-color: #ff0000;">packagesToScan</span>">
- <list>
- <value>com.bjsxt.model</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">
- org.hibernate.dialect.MySQLDialect
- </prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- </bean>
0 0
- spring中整合hibernate
- spring+hibernate整合,更新中。。。
- myeclipse中整合spring与hibernate
- Spring整合Hibernate中自动建表
- Spring整合hibernate中Application.xml
- springmvc+hibernate+spring在maven中整合
- spring整合hibernate中遇到的坑
- Spring:Spring整合Hibernate
- 【Spring】Spring+hibernate整合
- ssh整合:将hibernate的配置信息,配置到Spring的配置文件中(Spring整合hibernate)
- struts整合spring整合hibernate
- spring 整合hibernate整合方式
- 整合 struts spring hibernate
- struts+spring+hibernate整合
- struts,hibernate,spring整合
- struts+spring+hibernate整合
- struts+spring+hibernate整合
- Spring+hibernate+DWR整合
- 死锁产生的原因及四个必要条件
- IIS 7 HTTP 错误 500.19 - Internal Server Error
- java.util.ResourceBundle使用详解
- 【解惑】Java动态绑定机制的内幕
- ADC器件性能指标与选取1
- spring中整合hibernate
- IOS 动画
- Unity游戏开发之“屏幕截图”
- hdu3652(数位dp)
- IndentationError: unindent does not match any outer indentation level
- 《Javascript权威指南》学习笔记二之变量
- jsp中的session
- SVN:show log no date的两种解决方法
- java数据连接池的并发探讨