Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
来源:互联网 发布:旧电脑装linux服务器 编辑:程序博客网 时间:2024/05/16 09:42
本文主要记录spring整合hibernate的时候,直接使用hibernate.cfg.xml文件注入SessionFactory,applicationContext.xml文件配置如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocations"> <value>classpath:hibernate.cfg.xml</value> </property> </bean> <bean id="userDao" class="com.dao.impl.UserDaoImpl" > <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="userService" class="com.service.UserService" > <property name="userDao" ref="userDao"></property> </bean> </beans>
hibernate.cfg.xml配置文件如下:
<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property> <property name="connection.username">root</property> <property name="connection.password">***</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">10</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <property name="format_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <mapping resource="com/model/User.hbm.xml"/><!-- <mapping class="com.model.User"/>--> </session-factory></hibernate-configuration>
配置的核心就是:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocations"> <value>classpath:hibernate.cfg.xml</value> </property> </bean>
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- Spring整合Hibernate的时候使用hibernate.cfg.xml
- spring整合hibernate(无hibernate.cfg.xml)
- Spring整合Hibernate的时候使用hibernate.cfg.xml的区别
- spring整合hibernate不带有hibernate.cfg.xml(推荐使用)
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- Hibernate.cfg.xml 配置
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- 配置hibernate.cfg.xml
- hibernate.cfg.xml配置
- hibernate.cfg.xml配置
- javascript:使用ice.validate验证表单
- 产生a到b的随机数
- Does Android Support Dual-Cores or Multi-Cores Processor
- 获取当前进程的绝对路径
- 杂想的料
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- python脚本语言
- 常见的排序算法
- 最大堆的调整
- c++ static变量小结
- Android环境搭建及相关命令
- Java 类加载器和代理
- Python脚本解决在游戏开发中的困难
- Android UI学习 - Linear Layout, RelativeLayout