`
fu80008
  • 浏览: 19012 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

从应用角度看Hibernate源码(一):Hibernate配置文件

阅读更多

         Hibernate可以说伴随着我的整个Java历程。从我一开始工作,我就在一次意外的机会认识了它。以前,在使用语言上我是非常激进的。因为公司不采用Hibernate,我辞去了两份工作。可今天我们搞门户网站的时候,我却第一个反对使用Hibernate。总之,Hibernate让我彻夜难眠。

        刚开始接触Hibernate时,自然就要接触Hibernate配置文件,众所周知,Hibernate有两种配置模式:一个采用属性文件,一个采用XML配置文件。一般在早期Hibernate2时,大家都喜欢采用属性文件,现在大家都喜欢用XML配置文件。现在不妨贴一段基本XML配置给大家看看:

java 代码
  1. <?xml version='1.0' encoding='UTF-8'?>   
  2. <!DOCTYPE hibernate-configuration PUBLIC   
  3.           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  4.           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">   
  5.   
  6. <!-- Generated by MyEclipse Hibernate Tools.                   -->   
  7. <hibernate-configuration>   
  8.   
  9.     <session-factory>   
  10.         <property name="dialect">   
  11.             org.hibernate.dialect.MySQLDialect   
  12.         </property>   
  13.         <property name="connection.url">   
  14.             jdbc:mysql://localhost:3306/hibtest   
  15.         </property>   
  16.         <property name="connection.username">root</property>   
  17.         <property name="connection.driver_class">   
  18.             com.mysql.jdbc.Driver   
  19.         </property>   
  20.         <property name="hibernate.fetch">true</property>   
  21.         <property name="hibernate.show_sql">true</property>   
  22.         <property name="hibernate.cache.use_query_cache">true</property>   
  23.         <property name="hibernate.cache.provider_class">   
  24.             org.hibernate.cache.EhCacheProvider   
  25.         </property>   
  26.         <mapping resource="hib/pojo/Canguan.hbm.xml" />   
  27.         <mapping resource="hib/pojo/Kecheng.hbm.xml" />   
  28.         <mapping resource="hib/pojo/Reply.hbm.xml" />   
  29.         <mapping resource="com/edong/pojo/SongGame.hbm.xml" />   
  30.     </session-factory>   
  31.   
  32. </hibernate-configuration>  

上面这段代码,在一般的Hibernate使用者来说再也普通不过了。但如果从本质上去看待这些文件,能够看到很多内容。


(1)作为一个XML首先要注意的就是它的结构。 Hibernate 结构是由hibernate-configuration-3.0.dtd决定的。打开dtd文件自然就可以看到dtd结构。由于篇幅限制,读者可以在源码的src\org\hibernate目录下找到该文件。如果用户对这些dtd不熟悉,可以去看源码\etc目录下的配置demo。如果你还觉得不够, 可以采用Eclipse的提示去达到自己的目的。

(2)大家要注意的是,作为一个配置文件开始的第一个标签是不动的。同样对于以上的配置文件来说,<hibernate-configuration>元素是全局元素。

先吃饭去了,过会儿再继续

分享到:
评论
20 楼 zhouzhibo 2007-12-04  
写得不错,顶
19 楼 javachs 2007-10-10  
写的不错,顶,眼高手低者务扰。
18 楼 fu80008 2007-10-09  
谢谢,兄台的关注。
17 楼 fuwang 2007-10-09  
不是啊,我觉得你写得很好,那个投隐藏的太可耻了。
你写了这么多条,全部都切合"从应用角度看hibernate源码"的主题,虽然有几条稍微浅显点,但总的来说,对那些刚入门者、甚至用了几年hibernate的人都极具启发意义。当然,对于那些"不屑编码"者,"忽悠"者,确实没有用。我觉得这是篇很好的帖子,希望楼主继续(可另开帖)。
还有我建议你再开专栏时,尽量把前面几楼、甚至首页自己给占了,免得让别人说废话,影响气氛。
16 楼 fu80008 2007-10-09  
大哥,就这样吧。别难为我了,你要是觉得合适你也可以去开辟一个专栏试试。
15 楼 fuwang 2007-10-09  
你怎么能说别人不懂hibernate呢,几百万上千万的项目都是这样的人做出来的!
14 楼 fu80008 2007-10-09  
好酒不怕巷子深。只要是好东西,会有人发现的。至于Hibernate的优劣,也懒得去讨论了,一般没有什么结果。就是一帮不懂的人在瞎侃。没劲
    这个帖子就写到这儿吧,如果有什么好的思想,大家可以来补充。
13 楼 myyate 2007-10-09  
奇怪,这个帖子写的还可以吧,怎么投隐藏了?
12 楼 fuwang 2007-10-09  
fu80008 写道
这个帖子,不是对Hibernate性能的讨论,这里只做简单的介绍。Hibernate有很多致命的弱点。最重要的是Hibernate是单库(可以说单实例)解决方案。尽管Hibernate现在除了一个新的多库解决方案。但目前是不成熟的。
   就写这么多吧。我怕引发争议,偏离了主题。

我也觉得这是hibernate一个很值得讨论的问题。
你能否以此为主题另开新贴,让高手们都来参与一下。
11 楼 fu80008 2007-10-08  
(7)这个文件是怎样被加载到Hibernate的处理系统的呢?是通过org.hibernate.cfg.Configuration的。请看下面源码(只解释几个重要的方法)

public class Configuration implements Serializable {
 ......
}

  这个配置文件是是序列化的,其实Hibernate把全局的类对象都给序列化了。
public Configuration addJar(File jar) throws MappingException {
		log.info( "Searching for mapping documents in jar: " + jar.getName() );
		JarFile jarFile = null;
		try {
			try {
				jarFile = new JarFile( jar );
			}
			catch (IOException ioe) {
				throw new InvalidMappingException(
						"Could not read mapping documents from jar: " + jar.getName(), "jar", jar.getName(),
						ioe
				);
			}
			Enumeration jarEntries = jarFile.entries();
			while ( jarEntries.hasMoreElements() ) {
				ZipEntry ze = (ZipEntry) jarEntries.nextElement();
				if ( ze.getName().endsWith( ".hbm.xml" ) ) {
					log.info( "Found mapping document in jar: " + ze.getName() );
					try {
						addInputStream( jarFile.getInputStream( ze ) );
					}
					catch (Exception e) {
						throw new InvalidMappingException(
								"Could not read mapping documents from jar: " + jar.getName(),
								"jar",
								jar.getName(),
								e
						);
					}
				}
			}
		}
		finally {
			try {
				if ( jarFile != null ) {
					jarFile.close();
				}
			}
			catch (IOException ioe) {
				log.error("could not close jar", ioe);
			}
		}

		return this;
	}


这个方法是我们不常用的方法,用于加载jar包里面*.hbm.xml文件。其实我们从中学到的不仅仅是Hibernate的一个功能,而是学到了如何对Jar文件进行合理的操作。如果有一天需要对jar文件进行操作,到Hibernate源码里看看就行了。
10 楼 fu80008 2007-10-08  
这个帖子,不是对Hibernate性能的讨论,这里只做简单的介绍。Hibernate有很多致命的弱点。最重要的是Hibernate是单库(可以说单实例)解决方案。尽管Hibernate现在除了一个新的多库解决方案。但目前是不成熟的。
   就写这么多吧。我怕引发争议,偏离了主题。
9 楼 fuwang 2007-10-08  
感谢你讲了一些一般人不会注意而实际上很有用的东西,但大家最关心的是你为什么反对在门户网站使用Hibernate。
8 楼 fu80008 2007-10-08  
javachs 写道
secondPassCompile(); 

这句话啥意思,我看源码时没找到出处。


我用的是版本3.2,源码是这样
protected void secondPassCompile() throws MappingException {
		log.debug( "processing extends queue" );

		processExtendsQueue();

		log.debug( "processing collection mappings" );

		Iterator iter = secondPasses.iterator();
		while ( iter.hasNext() ) {
			SecondPass sp = (SecondPass) iter.next();
			if ( ! (sp instanceof QuerySecondPass) ) {
				sp.doSecondPass( classes ); 
				iter.remove();
			}
		}

		log.debug( "processing native query and ResultSetMapping mappings" );
		iter = secondPasses.iterator();
		while ( iter.hasNext() ) {
			SecondPass sp = (SecondPass) iter.next();
			sp.doSecondPass( classes ); 
			iter.remove();
		}

		log.debug( "processing association property references" );

		iter = propertyReferences.iterator();
		while ( iter.hasNext() ) {
			Mappings.PropertyReference upr = (Mappings.PropertyReference) iter.next();

			PersistentClass clazz = getClassMapping( upr.referencedClass );
			if ( clazz == null ) {
				throw new MappingException(
						"property-ref to unmapped class: " +
						upr.referencedClass
					);
			}

			Property prop = clazz.getReferencedProperty( upr.propertyName );
			if ( upr.unique ) {
				( (SimpleValue) prop.getValue() ).setAlternateUniqueKey( true );
			}
		}

		//TODO: Somehow add the newly created foreign keys to the internal collection

		log.debug( "processing foreign key constraints" );

		iter = getTableMappings();
		Set done = new HashSet();
		while ( iter.hasNext() ) {
			secondPassCompileForeignKeys( (Table) iter.next(), done );
		}

	}


  意图非常的明显,重新加载各种属性,在源码中被多次用到。
7 楼 fu80008 2007-10-08  
让我再去吃点东西吧,领导老瞄着我的屏幕。哈哈
6 楼 fu80008 2007-10-08  
(6)打开org.hibernate.Dialect目录还有一件让人兴奋的事情。Hibernate对Mysql的数据库作了区分,如MySQL5Dialect、MySQLDialect、MySQLInnoDBDialect等等。打开MySQL5Dialect代码
public class MySQL5Dialect extends MySQLDialect {
	protected void registerVarcharTypes() {
		registerColumnType( Types.VARCHAR, "longtext" );
		registerColumnType( Types.VARCHAR, 16777215, "mediumtext" );
		registerColumnType( Types.VARCHAR, 65535, "varchar($l)" );
	}
}

从以上代码,你可以知道,MySQL4和MySQL5之间有什么区别。更重要的它告诉了你,Hibernate Dialect是可以扩展的。只要你继承自己所需要的方言就可以扩展自己的函数,或者Mysql方言没有注册的MySQL函数。
5 楼 fu80008 2007-10-08  
(4)SessionFacotry相信大家都用过。在配置时,往往因找不到下面的属性配置,而在网络上东找西找。其实非常简单,只需要打开源码下的\etc\hibernate.properties,真是要啥有啥。而且肯定不用怀疑是否准确。同时Hibernate支持多少种数据库也尽收眼底。
(5)介绍一个重要的属性-dialect。做数据库语句查询时,大家都知道dialect是数据库的方言,但是,当不知道一个Hibernate的HQL函数而抓耳挠腮时,却不知道打开Hibernate方言看看。打开Hibernate所对用的方言。会发现里面挂满了Hibernate所能支持函数的全部。不相信看看如下的Mysql的方言。

public MySQLDialect() {
		super();
		registerColumnType( Types.BIT, "bit" );
		registerColumnType( Types.BIGINT, "bigint" );
		registerColumnType( Types.SMALLINT, "smallint" );
		registerColumnType( Types.TINYINT, "tinyint" );
		registerColumnType( Types.INTEGER, "integer" );
		registerColumnType( Types.CHAR, "char(1)" );
		registerColumnType( Types.FLOAT, "float" );
		registerColumnType( Types.DOUBLE, "double precision" );
		registerColumnType( Types.DATE, "date" );
		registerColumnType( Types.TIME, "time" );
		registerColumnType( Types.TIMESTAMP, "datetime" );
		registerColumnType( Types.VARBINARY, "longblob" );
		registerColumnType( Types.VARBINARY, 16777215, "mediumblob" );
		registerColumnType( Types.VARBINARY, 65535, "blob" );
		registerColumnType( Types.VARBINARY, 255, "tinyblob" );
		registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
		registerColumnType( Types.BLOB, "longblob" );
		registerColumnType( Types.BLOB, 16777215, "mediumblob" );
		registerColumnType( Types.BLOB, 65535, "blob" );
		registerColumnType( Types.CLOB, "longtext" );
		registerColumnType( Types.CLOB, 16777215, "mediumtext" );
		registerColumnType( Types.CLOB, 65535, "text" );
		registerVarcharTypes();

		registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
		registerFunction("bin", new StandardSQLFunction("bin", Hibernate.STRING) );
		registerFunction("char_length", new StandardSQLFunction("char_length", Hibernate.LONG) );
		registerFunction("character_length", new StandardSQLFunction("character_length", Hibernate.LONG) );
		registerFunction("lcase", new StandardSQLFunction("lcase") );
		registerFunction("lower", new StandardSQLFunction("lower") );
		registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG) );
		registerFunction("ltrim", new StandardSQLFunction("ltrim") );
		registerFunction("ord", new StandardSQLFunction("ord", Hibernate.INTEGER) );
		registerFunction("quote", new StandardSQLFunction("quote") );
		registerFunction("reverse", new StandardSQLFunction("reverse") );
		registerFunction("rtrim", new StandardSQLFunction("rtrim") );
		registerFunction("soundex", new StandardSQLFunction("soundex") );
		registerFunction("space", new StandardSQLFunction("space", Hibernate.STRING) );
		registerFunction("ucase", new StandardSQLFunction("ucase") );
		registerFunction("upper", new StandardSQLFunction("upper") );
		registerFunction("unhex", new StandardSQLFunction("unhex", Hibernate.STRING) );

		registerFunction("abs", new StandardSQLFunction("abs") );
		registerFunction("sign", new StandardSQLFunction("sign", Hibernate.INTEGER) );

		registerFunction("acos", new StandardSQLFunction("acos", Hibernate.DOUBLE) );
		registerFunction("asin", new StandardSQLFunction("asin", Hibernate.DOUBLE) );
		registerFunction("atan", new StandardSQLFunction("atan", Hibernate.DOUBLE) );
		registerFunction("cos", new StandardSQLFunction("cos", Hibernate.DOUBLE) );
		registerFunction("cot", new StandardSQLFunction("cot", Hibernate.DOUBLE) );
		registerFunction("crc32", new StandardSQLFunction("crc32", Hibernate.LONG) );
		registerFunction("exp", new StandardSQLFunction("exp", Hibernate.DOUBLE) );
		registerFunction("ln", new StandardSQLFunction("ln", Hibernate.DOUBLE) );
		registerFunction("log", new StandardSQLFunction("log", Hibernate.DOUBLE) );
		registerFunction("log2", new StandardSQLFunction("log2", Hibernate.DOUBLE) );
		registerFunction("log10", new StandardSQLFunction("log10", Hibernate.DOUBLE) );
		registerFunction("pi", new NoArgSQLFunction("pi", Hibernate.DOUBLE) );
		registerFunction("rand", new NoArgSQLFunction("rand", Hibernate.DOUBLE) );
		registerFunction("sin", new StandardSQLFunction("sin", Hibernate.DOUBLE) );
		registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE) );
		registerFunction("tan", new StandardSQLFunction("tan", Hibernate.DOUBLE) );

		registerFunction("radians", new StandardSQLFunction("radians", Hibernate.DOUBLE) );
		registerFunction("degrees", new StandardSQLFunction("degrees", Hibernate.DOUBLE) );

		registerFunction("ceiling", new StandardSQLFunction("ceiling", Hibernate.INTEGER) );
		registerFunction("ceil", new StandardSQLFunction("ceil", Hibernate.INTEGER) );
		registerFunction("floor", new StandardSQLFunction("floor", Hibernate.INTEGER) );
		registerFunction("round", new StandardSQLFunction("round", Hibernate.INTEGER) );

		registerFunction("datediff", new StandardSQLFunction("datediff", Hibernate.INTEGER) );
		registerFunction("timediff", new StandardSQLFunction("timediff", Hibernate.TIME) );
		registerFunction("date_format", new StandardSQLFunction("date_format", Hibernate.STRING) );

		registerFunction("curdate", new NoArgSQLFunction("curdate", Hibernate.DATE) );
		registerFunction("curtime", new NoArgSQLFunction("curtime", Hibernate.TIME) );
		registerFunction("current_date", new NoArgSQLFunction("current_date", Hibernate.DATE, false) );
		registerFunction("current_time", new NoArgSQLFunction("current_time", Hibernate.TIME, false) );
		registerFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP, false) );
		registerFunction("date", new StandardSQLFunction("date", Hibernate.DATE) );
		registerFunction("day", new StandardSQLFunction("day", Hibernate.INTEGER) );
		registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", Hibernate.INTEGER) );
		registerFunction("dayname", new StandardSQLFunction("dayname", Hibernate.STRING) );
		registerFunction("dayofweek", new StandardSQLFunction("dayofweek", Hibernate.INTEGER) );
		registerFunction("dayofyear", new StandardSQLFunction("dayofyear", Hibernate.INTEGER) );
		registerFunction("from_days", new StandardSQLFunction("from_days", Hibernate.DATE) );
		registerFunction("from_unixtime", new StandardSQLFunction("from_unixtime", Hibernate.TIMESTAMP) );
		registerFunction("hour", new StandardSQLFunction("hour", Hibernate.INTEGER) );
		registerFunction("last_day", new StandardSQLFunction("last_day", Hibernate.DATE) );
		registerFunction("localtime", new NoArgSQLFunction("localtime", Hibernate.TIMESTAMP) );
		registerFunction("localtimestamp", new NoArgSQLFunction("localtimestamp", Hibernate.TIMESTAMP) );
		registerFunction("microseconds", new StandardSQLFunction("microseconds", Hibernate.INTEGER) );
		registerFunction("minute", new StandardSQLFunction("minute", Hibernate.INTEGER) );
		registerFunction("month", new StandardSQLFunction("month", Hibernate.INTEGER) );
		registerFunction("monthname", new StandardSQLFunction("monthname", Hibernate.STRING) );
		registerFunction("now", new NoArgSQLFunction("now", Hibernate.TIMESTAMP) );
		registerFunction("quarter", new StandardSQLFunction("quarter", Hibernate.INTEGER) );
		registerFunction("second", new StandardSQLFunction("second", Hibernate.INTEGER) );
		registerFunction("sec_to_time", new StandardSQLFunction("sec_to_time", Hibernate.TIME) );
		registerFunction("sysdate", new NoArgSQLFunction("sysdate", Hibernate.TIMESTAMP) );
		registerFunction("time", new StandardSQLFunction("time", Hibernate.TIME) );
		registerFunction("timestamp", new StandardSQLFunction("timestamp", Hibernate.TIMESTAMP) );
		registerFunction("time_to_sec", new StandardSQLFunction("time_to_sec", Hibernate.INTEGER) );
		registerFunction("to_days", new StandardSQLFunction("to_days", Hibernate.LONG) );
		registerFunction("unix_timestamp", new StandardSQLFunction("unix_timestamp", Hibernate.LONG) );
		registerFunction("utc_date", new NoArgSQLFunction("utc_date", Hibernate.STRING) );
		registerFunction("utc_time", new NoArgSQLFunction("utc_time", Hibernate.STRING) );
		registerFunction("utc_timestamp", new NoArgSQLFunction("utc_timestamp", Hibernate.STRING) );
		registerFunction("week", new StandardSQLFunction("week", Hibernate.INTEGER) );
		registerFunction("weekday", new StandardSQLFunction("weekday", Hibernate.INTEGER) );
		registerFunction("weekofyear", new StandardSQLFunction("weekofyear", Hibernate.INTEGER) );
		registerFunction("year", new StandardSQLFunction("year", Hibernate.INTEGER) );
		registerFunction("yearweek", new StandardSQLFunction("yearweek", Hibernate.INTEGER) );

		registerFunction("hex", new StandardSQLFunction("hex", Hibernate.STRING) );
		registerFunction("oct", new StandardSQLFunction("oct", Hibernate.STRING) );

		registerFunction("octet_length", new StandardSQLFunction("octet_length", Hibernate.LONG) );
		registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.LONG) );

		registerFunction("bit_count", new StandardSQLFunction("bit_count", Hibernate.LONG) );
		registerFunction("encrypt", new StandardSQLFunction("encrypt", Hibernate.STRING) );
		registerFunction("md5", new StandardSQLFunction("md5", Hibernate.STRING) );
		registerFunction("sha1", new StandardSQLFunction("sha1", Hibernate.STRING) );
		registerFunction("sha", new StandardSQLFunction("sha", Hibernate.STRING) );

		registerFunction( "concat", new StandardSQLFunction( "concat", Hibernate.STRING ) );

		getDefaultProperties().setProperty(Environment.MAX_FETCH_DEPTH, "2");
		getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
	}

看到这些,如果你不是很笨,应该明白是怎么一回事了吧。
4 楼 javachs 2007-10-08  
secondPassCompile(); 

这句话啥意思,我看源码时没找到出处。
3 楼 javachs 2007-10-08  
把你前后对hibernate的态度的巨大变化讲一下,是啥让你变了心。
2 楼 fu80008 2007-10-08  
幸亏楼上的老兄提醒。这才发现自己吃了一天了,终于,吃饱了,喝足了。接着说。哈哈!
    续:如果发现开始元素不唯一,建议拆分成多个文件。
(3)通过观察环境dtd文件你会发现,<session-factory>元素是唯一的。这就表明一个配置文件可以创建一个sessionFacotry,也同时表示一个配置环境中可以连接一个的数据库。如果不放心,可以去看org.hibernate.cfg.Configuration下的
public SessionFactory buildSessionFactory() throws HibernateException {
		log.debug( "Preparing to build session factory with filters : " + filterDefinitions );
		secondPassCompile();
		validate();
		Environment.verifyProperties( properties );
		Properties copy = new Properties();
		copy.putAll( properties );
		PropertiesHelper.resolvePlaceHolders( copy );
		Settings settings = buildSettings( copy );

		return new SessionFactoryImpl(
				this,
				mapping,
				settings,
				getInitializedEventListeners()
			);
	}

这个方法在配置文件下,不带参数创建SessionFactory,肯定表明是唯一性。
1 楼 zhufanamo 2007-10-08  
你吃了一天了?

相关推荐

    hibernate 源码直接导入Eclipse

    - Configuration:配置对象,负责读取Hibernate配置文件(hibernate.cfg.xml),设置连接信息等。 - SessionFactory:会话工厂,根据Configuration对象生成,是线程安全的,用于创建Session实例。 - Session:...

    hibernate学习一:简单应用1配置文件版

    本篇文章将探讨“Hibernate学习一:简单应用1配置文件版”,主要涵盖如何配置Hibernate,创建实体类,以及进行基本的CRUD操作。 首先,我们来了解Hibernate的核心配置文件——`hibernate.cfg.xml`。这个文件包含了...

    Hibernate源码解析(一)

    《Hibernate源码解析(一)》 在Java开发领域,Hibernate作为一款强大的对象关系映射(ORM)框架,极大地简化了数据库操作。深入理解Hibernate的源码,不仅可以帮助开发者更好地运用该工具,还能提升对Java编程和...

    Hibernate3.1_学习源码

    配置文件:只配置父类的映射文件,在其中加入joined-subclass将两个子类实体映射关系添加 2) 数据库表:一张表,包括公共字段、特有字段、区分字段 实体层设计:与第一种方法设计一样,设计三个实体类,分父类和...

    hibernate源码 直接使用

    标题"hibernate源码 直接使用"表明我们将探讨的是Hibernate框架的源代码,以及如何直接在项目中应用这些源代码。Hibernate是一个流行的Java ORM(对象关系映射)框架,它简化了数据库操作,将数据库交互转化为面向...

    精通hibernate源码ch2

    在深入探讨Hibernate源码之前,我们首先需要理解什么是对象持久化技术。对象持久化是将内存中的对象状态保存到持久存储介质(如数据库)中,以便在后续的程序运行中可以恢复这些对象的状态。它解决了应用程序中的...

    传智播客hibernate源码

    标题"传智播客hibernate源码"暗示了这是一个关于Hibernate框架的源代码学习资源,可能包含了对Hibernate框架内部机制的深入解析,以及如何在实际项目中应用Hibernate的相关示例。 描述中的内容重复,进一步确认了这...

    Hibernate入门案例源码

    【Hibernate入门案例源码】是针对初学者设计的一份教程,旨在帮助理解并掌握Java持久化框架Hibernate的基础应用。Hibernate是一个强大的ORM(对象关系映射)框架,它简化了数据库与Java对象之间的交互,使开发者可以...

    Hibernate性能优化:一级缓存

    压缩包文件“hibernate_cache_level1”可能包含与一级缓存相关的示例代码、配置文件或文档,可以帮助开发者更深入地理解一级缓存的实现和优化。例如,其中可能有示例展示了如何配置SessionFactory的缓存区域大小,...

    hibernate tools源码运行或修改需要的jar

    7. **逆向工程**:Hibernate Tools支持从现有数据库生成Java实体类和映射文件,这在快速构建数据驱动的应用时非常有用。 8. **代码生成**:它可以根据实体类自动生成DAO和Service层的模板代码,减少手动编写的工作...

    精通Hibernate源码.rar

    本文将从多个角度探讨Hibernate源码中的核心概念和实现机制。 1. **持久化模型设计** Hibernate通过Java类和数据库表之间的映射(Mapping),实现了对象的持久化。在源码中,`hibernate.cfg.xml`配置文件定义了...

    hibernate源码分析一[启动过程]

    总的来说,Hibernate的启动过程涉及多个核心类和接口的协作,从配置文件的读取解析到`SessionFactory`的创建,每一步都至关重要,深刻理解这一流程对于掌握Hibernate框架的应用和优化具有重要意义。

    hibernate源码

    配置完成后,可以使用`buildSessionFactory`方法创建SessionFactory,它是线程安全的,一个应用程序通常只需要一个SessionFactory实例。 接下来,实体类是Hibernate工作的基础。实体类通常对应数据库中的表,类中的...

    Hibernate源码

    【标题】"Hibernate源码"涉及的是Java领域中著名的对象关系映射(ORM)框架Hibernate的核心源代码。ORM框架允许开发者使用面向对象的方式来操作数据库,而无需直接编写SQL语句,极大地提高了开发效率和代码可读性。...

    hibernate源码分析过程

    Hibernate 的配置可以通过多种方式实现,包括配置文件、可编程配置和 JNDI绑定。配置文件可以是 XML 文件或 properties 文件,用于指定数据库连接信息、映射文件路径等信息。可编程配置可以在运行时动态生成配置信息...

    hibernate源码包

    2. **org.hibernate.cfg**: 配置相关的类,如Configuration,用于加载Hibernate配置文件,建立SessionFactory。Environment类中定义了一些常量,比如连接数据库所需的属性。 3. **org.hibernate.cache**: 缓存管理...

    hibernate源码的学习

    在Hibernate源码的学习过程中,我们可以深入理解ORM的工作原理,提高我们的Java开发技能,并且能够更好地优化数据库操作。 一、Hibernate核心组件 1. Configuration:配置对象,负责读取hibernate.cfg.xml文件,...

Global site tag (gtag.js) - Google Analytics