- 浏览: 260057 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (87)
- Java (6)
- Frameworks (1)
- JavaWeb (3)
- Spring (6)
- Hibernate (26)
- Maven (2)
- Plugin (1)
- Velocity (1)
- Freemarker (1)
- Spring security (18)
- Google (5)
- Guice (5)
- rmi (1)
- Annotation (1)
- Binding (1)
- commons-fileupload (3)
- fileupload (3)
- ehcache (1)
- ApplicationContext (1)
- Resource (1)
- Validator (1)
- PropertyEditor (1)
- one-to-many (5)
- cascade (2)
- MessageSource (1)
- Serialize (1)
- Serializable (1)
- delete (1)
- delete-orphan (1)
- fetch (1)
- one-to-one (1)
- join (4)
- DomainObject (1)
- CRUD (1)
- composite-element (1)
- Hibernate ORM (14)
- dynamic-insert (1)
- dynamic-update (1)
- Search (1)
- DDD (0)
- Job (0)
- element (1)
- Unique (1)
- Group (1)
- tomcat (1)
- https (1)
- mysql (1)
最新评论
-
xurunchengof:
[url][url][url][img][img][img][ ...
Spring Security 3多用户登录实现之三 验证过滤器 -
Wind_ZhongGang:
yo8237233 写道你这样的话如果上传文件超过了50000 ...
Spring集成Commons fileupload,文件上传 -
yo8237233:
你这样的话如果上传文件超过了50000000就会报异常
Spring集成Commons fileupload,文件上传 -
zhuzhiguosnail:
Wind_ZhongGang 写道lianglaiyang 写 ...
Spring Security 3多用户登录实现一 -
曾老师:
?????
Spring Security 3用户登录实现之十 用户切换
对于Hibernate的配置方式,有三种,一种是通过外部的属性文件进行配置,一种是通过外部的xml文件进行配置,还有一种就是通过编程的方式进行配置,但对于编程式配置来说,不便于参数的集中管理与修改,所以这里主要介绍两种外部文件的配置方式。
一。属性文件配置方式
hibernate.connection.url=jdbc:mysql://localhost:3306/couple?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8 hibernate.connection.driver_class=com.mysql.jdbc.Driver hibernate.connection.username=root hibernate.connection.password=root hibernate.dialect=org.hibernate.dialect.MySQL5Dialect hibernate.current_session_context_class=thread hibernate.cache.use_second_level_cache=false hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider hibernate.jdbc.batch_size=100 hibernate.jdbc.fetch_size=10 hibernate.show_sql=true hibernate.hbm2ddl.auto=update hibernate.format_sql=true hibernate.use_sql_comments=true
二。xml文件配置方式
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/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/couple?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8</property> <property name="connection.username">root</property> <property name="connection.password">root</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!--<property name="connection.autocommit">true</property>--> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.use_second_level_cache">false</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="jdbc.batch_size">100</property> <property name="jdbc.fetch_size">10</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Format all executed SQL to stdout --> <property name="format_sql">true</property> <property name="use_sql_comments">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <mapping resource="hibernate/mappings/Person.hbm.xml"/> </session-factory> </hibernate-configuration>
对于第一种外部配置文件方式,在创建sessionFactory时,以这样的方式调用new Configuration().buildSessionFactory(),它会寻找项目中名为hibernate.properties的文件,研究源码就可以发现在Environment类中有这样的一行代码InputStream stream = ConfigHelper.getResourceAsStream("/hibernate.properties");,因为这是写死在Hibernate中的,所以这样的文件名是不可改动的。
对于第二种外部配置文件方式,在创建sessionFactory时,以这样的方式调用new Configuration().configure().buildSessionFactory(),默认在没有设置xml配置文件的位置的情况下,会去查找名为hibernate.cfg.xml的配置文件,研究源码就可以发现在Configuration类中有这样的一段代码
public Configuration configure() throws HibernateException {
configure( "/hibernate.cfg.xml" );
return this;
}
最后附上一个由Hibernate配置的mysql数据库项目模板实例,以供参考。
- HibernateCore.zip (24.5 KB)
- 下载次数: 14
发表评论
-
Hibernate unique使用
2011-11-28 22:16 1109在Hibernate中对于一对一的关联关系配置 ... -
Hibernate cascade在不同关联关系中的具体表现
2011-11-22 21:47 3086在Hibernate中,针对持久化实体的配置文件中有 ... -
Hibernate element使用
2011-11-20 20:43 1541一.Person package co ... -
Hibernate 单表实现树结构
2011-11-13 21:10 2794来看看通过单表来实现一个树形结构的方式。这里假设有这样 ... -
Hibernate save persist merge探究
2011-10-27 17:59 4084先来看看hibernate-reference.pd ... -
Hibernate Search配置及简单应用
2011-10-25 16:06 2539Hibernate Search是一款集成Apach ... -
dynamic-insert,dynamic-update 我有话要说
2011-10-21 17:39 12923在之前的一个项目中,Team leader说在每一个 ... -
Hibernate one-to-many composite-element实现
2011-10-17 16:55 2614Hibernate中持久化实体间一对多关联关系的compo ... -
基于DomainObject的通用数据库CRUD操作
2011-10-17 15:09 1564对于项目中的持久化实体,持久化实体虽然对应着不同的业务对象 ... -
Hibernate one-to-many 双方双向连接表关联
2011-10-17 14:24 1700Hibernate中持久化实体间一对多关联,具体关联关 ... -
Hibernate one-to-many 多方单向连接表关联
2011-10-15 23:37 1254Hibernate中持久化实体间一对多 ... -
Hibernate one-to-many 一方单向连接表关联
2011-10-15 23:17 1647Hibernate中对于持久化实体间的关联关系有 ... -
Hibernate one-to-one 两方双向连接表关联
2011-10-15 17:38 2716Hibernate中对于持久化实体间的关联关系有三种分类, ... -
Hibernate fetch 抓取策略
2011-09-27 18:20 1317Hibernate fetch抓取策略定义了当抓 ... -
Hibernate 关联关系解除
2011-09-27 13:46 1504Hibernate对于持久化实体间的关联关系解 ... -
Hibernate one-to-many cascade探究
2011-09-08 13:20 1119对于Hibernate的one-to-many关联关系中, ... -
Hibernate inverse 深度解析
2011-08-09 22:55 1232inverse 英文意思为反向,倒转的。 Hi ... -
Hibernate ORM one-to-one主键关联关系映射
2011-08-01 22:08 1348Hibernate ORM one-to-one映射主要有 ... -
Hibernate ORM Inheritance
2011-07-31 22:56 1318Hibernate ORM提供了三 ... -
Hibernate many-to-many
2011-07-30 17:20 1855对于持久化实体间多对多的关联关系,在数据库中的反映 ...
相关推荐
Hibernate连接池的三种配置方式......
给大家带来了hibernate4基本配置方式,非常不错,具有参考借鉴价值,需要的额朋友参考下吧
hibernate 连接池配置详解,四种连接方式:第一种方案,Hibernate默认连接池;第二种方案是:C3P0;第三种方案是:dbcp;第四种方案是:Proxool (推荐)
在myeclipse中配置hibernate 自动生成配置文件在myeclipse中配置hibernate 自动生成配置文件
hibernate连接池配置的三种方式。
Hibernate学习的必备,包含了Hibernate的配置文件,MySQL的连接jar文件
Spring-hibernate结合使用全xml配置方式
Hibernate4.0注解配置详解,Hibernate4.0注解配置详解,Hibernate4.0注解配置详解
Hibernate连接SQLite配置步骤: 1、添加SQLite库: 1.1、将两个jar包:com.zy.hibernate.dialect.SQLiteDialect.jar、sqlite-jdbc-3.7.2.jar拷贝到“\WEB-INF\lib”文件夹下; 2、配置hibernate: 2.1、将...
hibernate_esb配置
hibernate配置,详细的讲了hibernate用的配置文件和方法,可以哦
在hibernate中配置多数据库,并自由切换
hibernate_3配置文件参数汇总,在ssh开发中经常用到是hibernate_3配置
Hibernate配置详解,详细描述了Hibernate的配置文件,一对一 一对多,多对多的单双向配置详解。
Hibernate映射文件可选配置大全,协助开发很给力
配置了tomcat之后发现jndi好简单啊,可是碰到了hibernate该怎么做呢,本例详细解析
Hibernate配置文件中配置各种数据库的driver、URL
Hibernate_映射配置文件详解,很好用的学习文件
hibernate注解配置