hibernate 翻译

 

 

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-6183HHH-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 thisConfiguration 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 INSERTdelete() 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 UPDATEsaveOrUpdate() 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.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值