Configuration
An instance of Configuration allows(允许) the application to specify properties and mapping documents to be used when creating a SessionFactory. Usually(通常) an application will create a single Configuration, build a single instance of SessionFactoryand then instantiate Sessions in threads servicing client requests. The Configuration is meant(意味) only as an initialization(初始化)-time object. SessionFactorys are immutable(不可变) and do not retain(保留) any association(协会) back to the Configuration.
A new Configuration will use the properties specified in hibernate.properties by default.
NOTE : This will be replaced(取代) by use of ServiceRegistryBuilder
and MetadataSources
instead(替换) after the 4.0 release(发布) at which point this class will become deprecated and scheduled(预期) for removal in 5.0. See HHH-6183, HHH-2578 and HHH-6586 for details
buildSessionFactory
Create a SessionFactory
using the properties and mappings in this configuration. The SessionFactory
will be immutable(不可变), so changes made to this
Configuration
after building the SessionFactory
will not affect(影响) it.
SessionFactory
The main contract here is the creation of Session
instances. Usually an application has a single SessionFactory
instance and threads servicing(为...服务) client requests obtain(获得) Session
instances from this factory.
The internal state of a SessionFactory
is immutable. Once it is created this internal state is set. This internal state includes all of the metadata(元数据) about Object/Relational(相关的) Mapping.
Implementors(实施者) must be threadsafe.
Session
The main runtime interface between a Java application and Hibernate. This is the central API class abstracting the notion(概念) of a persistence(持续) service.
The lifecycle(生命周期) of a Session is bounded(有界限的) by the beginning and end of a logical transaction. (Long transactions might(可能) span(跨越) several(几个) database transactions.)
The main function of the Session is to offer(提供) create, read and delete operations for instances of mapped entity classes. Instances may exist in one of three states:
transient(瞬时): never persistent(持久的), not associated(相关) with any Session
persistent(持久): associated(关联) with a unique Session
detached(托管): previously(预先) persistent, not associated with any Session
Transient(瞬时) instances may be made persistent(持久) by calling save(), persist() or saveOrUpdate(). Persistent(持久) instances may be made transient by calling delete(). Any instance returned by a get() or load() method is persistent. Detached(托管) instances may be made persistent by calling update(), saveOrUpdate(), lock() orreplicate(). The state of a transient(瞬时) or detached(瞬时) instance may also be made persistent(持久) as a new persistent(持久) instance by calling merge().
save() and persist() result in an SQL INSERT, delete() in an SQL DELETE and update() or merge() in an SQL UPDATE. Changes to persistent instances are detected at flush time and also result in an SQL UPDATE. saveOrUpdate() and replicate() result in either an INSERT or an UPDATE.
It is not intended that implementors be threadsafe. Instead each thread/transaction should obtain its own instance from a SessionFactory.
A Session instance is serializable if its persistent classes are serializable.
A typical transaction should use the following idiom:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
If the Session throws an exception, the transaction must be rolled back and the session discarded. The internal state of the Session might not be consistent with the database after the exception occurs.
分享到:
相关推荐
在Hibernate翻译版中,读者可以了解到Hibernate的核心概念、配置、实体映射、会话管理、查询语言(HQL)以及事务处理等方面的知识。这为Java开发者提供了全面理解Hibernate的途径,使得数据库操作变得更加便捷和高效...
5. **antlr-2.7.7.jar**:ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。在Hibernate中,它用于解析HQL和Criteria API查询。 6. **dom4j-1.6.1.jar**:这是一个XML处理库,...
### Hibernate Annotations 翻译文档知识点解析 #### 一、文档概述 本文档是一份关于Hibernate Annotations的中文翻译资料,其版本为3.2.0CR1。此文档旨在为中文用户理解Hibernate Annotations提供帮助,并且它是...
包含翻译后的API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final; 标签:hibernate、javax、...
8. **antlr-runtime.jar**:ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,Hibernate使用它解析HQL和SQL。 9. **asm.jar**:字节码操作库,用于辅助生成和分析Java类。 在...
包含翻译后的API文档:hibernate-jpa-2.1-api-1.0.2.Final-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final; 标签:hibernate、...
Hibernate版本3的翻译由满江红翻译团队(RedSaga Translate Team)集体进行,这也是一次大规模网络翻译的试验。在不到20天的时间内,我们完成了两百多页文档的翻译,这一成果是通过十几位网友集体努力完成的。通过这次...
:最近我开始使用Eclipse作为我的开发环境,我开始研究其他人提供的对Eclipse的扩展。例如,当用到xml文件时,我使用XMLBuddy插件.在这篇文章中,我们将探索其中之一:Hibernate Synchronizer.。
5. **antlr-2.7.6.jar**:ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。在Hibernate中,ANTLR用于解析HQL(Hibernate Query Language)。 6. **log4j-1.2.12.jar**:Log4j是...
这个中文版的翻译工作为国内开发者提供了方便,使他们能更直观地理解和掌握Hibernate的核心概念与使用技巧。 Hibernate的主要功能在于将Java对象与数据库表进行映射,通过对象化的操作方式管理数据库,降低了数据层...
"Hibernate 3.5.2 中文API" 是针对该版本的Hibernate提供的官方API文档的中文翻译版,对于初学者和进阶者来说都是不可或缺的学习资源。 1. **对象关系映射(ORM)基础**:ORM的核心思想是将数据库中的表格映射为...
3. **Antlr**:Antlr是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。在Hibernate中,Antlr被用来解析HQL(Hibernate查询语言),这是一种面向对象的查询语言,类似于SQL,但与特定的...
5. `antlr-3.0ea8.jar`:ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。在Hibernate中,ANTLR主要用于解析HQL和JPQL。 6. `cglib-nodep-3.2.6.jar`:CGLIB是一个代码生成库,...
ANTLR(ANother Tool for Language Recognition)是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。在Hibernate中,ANTLR主要用于解析HQL(Hibernate Query Language)和SQL语句,生成...
8. **antlr-2.7.6.jar**:ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。Hibernate使用ANTLR来解析HQL和JPQL(Java Persistence Query Language)。 9. **dom4j-1.6.1.jar**...
这个文档可能由雷智民撰写或翻译,提供了一手的注解使用方法和实例。 综上所述,学习这些内容可以深入了解Hibernate框架,包括如何通过注解方式实现对象和数据库的映射,如何执行CRUD操作,以及如何使用HQL进行复杂...
6. **antlr-2.7.6.jar**: ANTLR(ANother Tool for Language Recognition)是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。Hibernate使用ANTLR来解析HQL(Hibernate Query Language...
4. **antlr-2.7.7.jar**:ANTLR 是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。在 Hibernate 中,它用于解析 HQL 和 JPQL 查询语句。 5. **c3p0-0.9.2.1.jar**:C3P0 数据源连接池...
8. **antlr-2.7.6.jar**:ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件。Hibernate使用ANTLR解析HQL(Hibernate Query Language)和JPQL(Java Persistence Query Language)...