翻譯hibernate---org.hibernate.session的API文檔

public interface Session extends SharedSessionContract,EntityManager,HibernateEntiryManager,AutoCloseable;

主要用于java 應(yīng)用和hibernate之間運(yùn)行時(shí)的接口萝招;這是一個(gè)核心的持久化服務(wù)API抽象類(lèi)概念惶翻;

一個(gè)session的生命周期主要由邏輯事務(wù)管理器的開(kāi)始和結(jié)束界定;

session的主要作用是為映射的實(shí)體類(lèi)實(shí)例提供create ,read and delete 操作渺绒;實(shí)例可能以下面三種方式的一種狀態(tài)存在:

transient:從不持久化,不與任何session關(guān)聯(lián)

persistent:與一個(gè)唯一性的session關(guān)聯(lián)

detached:前置持久,不與任何session關(guān)聯(lián)

transient實(shí)例可能通過(guò)調(diào)用sav(),persist(),or saveOrUpdate()進(jìn)行持久化峡捡;Persistent實(shí)例可能通過(guò)transient調(diào)用delete();任何實(shí)例返回一個(gè)由get()或者load()方法返回的持久化對(duì)象劣纲;Detached實(shí)例可能通過(guò)update(),saveOrUpdate(),lock() or replicate()進(jìn)行實(shí)例化逢捺;在transient or detached狀態(tài)下的實(shí)例也可以通過(guò)調(diào)用merge()方法,作為一個(gè)新的持久化對(duì)象進(jìn)行持久化癞季;

save()和persist()在SQL中執(zhí)行的結(jié)果是INSERT,delete()在SQL中執(zhí)行的結(jié)果是DELETE;update()或merge()在SQL中執(zhí)行的是UPDATE劫瞳。持久化實(shí)例在寫(xiě)入時(shí)間段被發(fā)現(xiàn)發(fā)生變化倘潜,且在SQL中執(zhí)行了UPDATE。saveOrUpdate()和replicate()執(zhí)行INSERT或者UPDATE中一種行為志于;

實(shí)現(xiàn)的類(lèi)并不是線(xiàn)程安全的涮因;因此,每個(gè)線(xiàn)程或者事務(wù)應(yīng)該從sessionfactory獲取自己的實(shí)例伺绽;

一個(gè)Session實(shí)例是序列化的养泡,如果他的持久類(lèi)是序列化的;

一個(gè)典型的事務(wù)管理應(yīng)該使用如下的格式:

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();

}

具體方法如下

All MethodsInstance MethodsAbstract MethodsDeprecated Methods

Modifier and TypeMethod and Description

voidaddEventListeners(SessionEventListener...?listeners)

Add one or more listeners to the Session

Session.LockRequestbuildLockRequest(LockOptionslockOptions)

Build a LockRequest that specifies the LockMode, pessimistic lock timeout and lock scope.

IdentifierLoadAccessbyId(Class?entityClass)

Create anIdentifierLoadAccessinstance to retrieve the specified entity by primary key.

IdentifierLoadAccessbyId(StringentityName)

Create anIdentifierLoadAccessinstance to retrieve the specified entity type by primary key.

MultiIdentifierLoadAccessbyMultipleIds(Class?entityClass)

Create aMultiIdentifierLoadAccessinstance to retrieve multiple entities at once as specified by primary key values.

MultiIdentifierLoadAccessbyMultipleIds(StringentityName)

Create aMultiIdentifierLoadAccessinstance to retrieve multiple entities at once as specified by primary key values.

NaturalIdLoadAccessbyNaturalId(Class?entityClass)

Create anNaturalIdLoadAccessinstance to retrieve the specified entity by its natural id.

NaturalIdLoadAccessbyNaturalId(StringentityName)

Create anNaturalIdLoadAccessinstance to retrieve the specified entity by its natural id.

SimpleNaturalIdLoadAccessbySimpleNaturalId(Class?entityClass)

Create anSimpleNaturalIdLoadAccessinstance to retrieve the specified entity by its simple (single attribute) natural id.

SimpleNaturalIdLoadAccessbySimpleNaturalId(StringentityName)

Create anSimpleNaturalIdLoadAccessinstance to retrieve the specified entity by its natural id.

voidcancelQuery()

Cancel the execution of the current query.

voidclear()

Completely clear the session.

booleancontains(StringentityName,Objectobject)

Check if this entity is associated with this Session.

QuerycreateFilter(Objectcollection,StringqueryString)

Create aQueryinstance for the given collection and filter string.

QuerycreateNamedQuery(Stringname,Class?resultType)

The JPA-defined named, typed query creation method.

QuerycreateQuery(CriteriaDeletedeleteQuery)

QuerycreateQuery(CriteriaQuery?criteriaQuery)

QuerycreateQuery(CriteriaUpdateupdateQuery)

QuerycreateQuery(StringqueryString)

Create aQueryinstance for the given HQL/JPQL query string.

QuerycreateQuery(StringqueryString,Class?resultType)

Create a typedQueryinstance for the given HQL/JPQL query string.

voiddelete(Objectobject)

Remove a persistent instance from the datastore.

voiddelete(StringentityName,Objectobject)

Remove a persistent instance from the datastore.

voiddisableFetchProfile(Stringname)

Disable a particular fetch profile on this session.

voiddisableFilter(StringfilterName)

Disable the named filter for the current session.

Connectiondisconnect()

Disconnect the session from its underlying JDBC connection.

?TdoReturningWork(ReturningWork?work)

Controller for allowing users to perform JDBC related work using the Connection managed by this Session.

voiddoWork(Workwork)

Controller for allowing users to perform JDBC related work using the Connection managed by this Session.

voidenableFetchProfile(Stringname)

Enable a particular fetch profile on this session.

FilterenableFilter(StringfilterName)

Enable the named filter for this current session.

voidevict(Objectobject)

Remove this instance from the session cache.

voidflush()

Force this session to flush.

?Tget(Class?entityType,Serializableid)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.

?Tget(Class?entityType,Serializableid,LockModelockMode)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.

?Tget(Class?entityType,Serializableid,LockOptionslockOptions)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.

Objectget(StringentityName,Serializableid)

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Objectget(StringentityName,Serializableid,LockModelockMode)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.

Objectget(StringentityName,Serializableid,LockOptionslockOptions)

Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.

CacheModegetCacheMode()

Get the current cache mode.

LockModegetCurrentLockMode(Objectobject)

Determine the current lock mode of the given object.

FiltergetEnabledFilter(StringfilterName)

Retrieve a currently enabled filter by name.

StringgetEntityName(Objectobject)

Return the entity name for a persistent entity.

FlushModeTypegetFlushMode()

For users of the Hibernate native APIs, we've had to rename this method as defined by Hibernate historically because the JPA contract defines a method of the same name, but returning the JPAFlushModeTyperather than Hibernate'sFlushMode.

FlushModegetHibernateFlushMode()

Get the current flush mode for this session.

SerializablegetIdentifier(Objectobject)

Return the identifier value of the given entity as associated with this session.

LobHelpergetLobHelper()

Retrieve this session's helper/delegate for creating LOB instances.

SessionFactorygetSessionFactory()

Get the session factory which created this session.

SessionStatisticsgetStatistics()

Get the statistics for this session.

TypeHelpergetTypeHelper()

Convenience access to theTypeHelperassociated with this session'sSessionFactory.

booleanisDefaultReadOnly()

Will entities and proxies that are loaded into this session be made read-only by default? To determine the read-only/modifiable setting for a particular entity or proxy:

booleanisDirty()

Does this session contain any changes which must be synchronized with the database? In other words, would any DML operations be executed if we flushed this session?

booleanisFetchProfileEnabled(Stringname)

Is a particular fetch profile enabled on this session?

booleanisReadOnly(ObjectentityOrProxy)

Is the specified entity or proxy read-only? To get the default read-only/modifiable setting used for entities and proxies that are loaded into the session:

?Tload(Class?theClass,Serializableid)

Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.

?Tload(Class?theClass,Serializableid,LockModelockMode)

Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

?Tload(Class?theClass,Serializableid,LockOptionslockOptions)

Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

voidload(Objectobject,Serializableid)

Read the persistent state associated with the given identifier into the given transient instance.

Objectload(StringentityName,Serializableid)

Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.

Objectload(StringentityName,Serializableid,LockModelockMode)

Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

Objectload(StringentityName,Serializableid,LockOptionslockOptions)

Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

voidlock(Objectobject,LockModelockMode)

Obtain the specified lock level upon the given object.

voidlock(StringentityName,Objectobject,LockModelockMode)

Obtain the specified lock level upon the given object.

Objectmerge(Objectobject)

Copy the state of the given object onto the persistent object with the same identifier.

Objectmerge(StringentityName,Objectobject)

Copy the state of the given object onto the persistent object with the same identifier.

voidpersist(Objectobject)

Make a transient instance persistent.

voidpersist(StringentityName,Objectobject)

Make a transient instance persistent.

voidreconnect(Connectionconnection)

Reconnect to the given JDBC connection.

voidrefresh(Objectobject)

Re-read the state of the given instance from the underlying database.

voidrefresh(Objectobject,LockModelockMode)

Re-read the state of the given instance from the underlying database, with the givenLockMode.

voidrefresh(Objectobject,LockOptionslockOptions)

Re-read the state of the given instance from the underlying database, with the givenLockMode.

voidrefresh(StringentityName,Objectobject)

Re-read the state of the given instance from the underlying database.

voidrefresh(StringentityName,Objectobject,LockOptionslockOptions)

Re-read the state of the given instance from the underlying database, with the givenLockMode.

voidreplicate(Objectobject,ReplicationModereplicationMode)

Persist the state of the given detached instance, reusing the current identifier value.

voidreplicate(StringentityName,Objectobject,ReplicationModereplicationMode)

Persist the state of the given detached instance, reusing the current identifier value.

Serializablesave(Objectobject)

Persist the given transient instance, first assigning a generated identifier.

Serializablesave(StringentityName,Objectobject)

Persist the given transient instance, first assigning a generated identifier.

voidsaveOrUpdate(Objectobject)

Eithersave(Object)orupdate(Object)the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

voidsaveOrUpdate(StringentityName,Objectobject)

Eithersave(String, Object)orupdate(String, Object)the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

SharedSessionBuildersessionWithOptions()

Obtain aSessionbuilder with the ability to grab certain information from this session.

voidsetCacheMode(CacheModecacheMode)

Set the cache mode.

voidsetDefaultReadOnly(boolean?readOnly)

Change the default for entities and proxies loaded into this session from modifiable to read-only mode, or from modifiable to read-only mode.

voidsetFlushMode(FlushModeflushMode)

Deprecated.

(since 5.2) usesetHibernateFlushMode(FlushMode)instead

voidsetHibernateFlushMode(FlushModeflushMode)

Set the flush mode for this session.

voidsetReadOnly(ObjectentityOrProxy, boolean?readOnly)

Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode.

voidupdate(Objectobject)

Update the persistent instance with the identifier of the given detached instance.

voidupdate(StringentityName,Objectobject)

Update the persistent instance with the identifier of the given detached instance.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末奈应,一起剝皮案震驚了整個(gè)濱河市澜掩,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌杖挣,老刑警劉巖肩榕,帶你破解...
    沈念sama閱讀 218,640評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異程梦,居然都是意外死亡点把,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,254評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)屿附,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)郎逃,“玉大人,你說(shuō)我怎么就攤上這事挺份“玻” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,011評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵匀泊,是天一觀的道長(zhǎng)优训。 經(jīng)常有香客問(wèn)我,道長(zhǎng)各聘,這世上最難降的妖魔是什么揣非? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,755評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮躲因,結(jié)果婚禮上早敬,老公的妹妹穿的比我還像新娘。我一直安慰自己大脉,他們只是感情好搞监,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,774評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著镰矿,像睡著了一般琐驴。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 51,610評(píng)論 1 305
  • 那天绝淡,我揣著相機(jī)與錄音宙刘,去河邊找鬼。 笑死牢酵,一個(gè)胖子當(dāng)著我的面吹牛荐类,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播茁帽,決...
    沈念sama閱讀 40,352評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼屈嗤!你這毒婦竟也來(lái)了潘拨?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,257評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤饶号,失蹤者是張志新(化名)和其女友劉穎铁追,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體茫船,經(jīng)...
    沈念sama閱讀 45,717評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡琅束,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,894評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了算谈。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片涩禀。...
    茶點(diǎn)故事閱讀 40,021評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖然眼,靈堂內(nèi)的尸體忽然破棺而出艾船,到底是詐尸還是另有隱情,我是刑警寧澤高每,帶...
    沈念sama閱讀 35,735評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響陨囊,放射性物質(zhì)發(fā)生泄漏镊绪。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,354評(píng)論 3 330
  • 文/蒙蒙 一带欢、第九天 我趴在偏房一處隱蔽的房頂上張望运授。 院中可真熱鬧,春花似錦洪囤、人聲如沸徒坡。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,936評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)喇完。三九已至,卻和暖如春剥啤,著一層夾襖步出監(jiān)牢的瞬間锦溪,已是汗流浹背不脯。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,054評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留刻诊,地道東北人防楷。 一個(gè)月前我還...
    沈念sama閱讀 48,224評(píng)論 3 371
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像则涯,于是被迫代替她去往敵國(guó)和親复局。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,974評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,478評(píng)論 5 6
  • 老大粟判,張國(guó) 張國(guó)最大也不過(guò)大我三歲亿昏,不過(guò)人長(zhǎng)的非常的成熟,那時(shí)候我們與一政府機(jī)關(guān)共享一個(gè)食堂档礁,食堂的工作人員都很勢(shì)...
    萬(wàn)能的老J閱讀 447評(píng)論 1 5
  • 好好說(shuō)話(huà)角钩,是門(mén)學(xué)問(wèn)。 成熟而準(zhǔn)確的語(yǔ)言體系呻澜,是人類(lèi)社會(huì)與動(dòng)物最大的區(qū)別之一递礼。語(yǔ)言幫助人們可以簡(jiǎn)單地表達(dá)自己的想法,...
    云夏KL閱讀 156評(píng)論 0 0
  • 梅雪爭(zhēng)春未肯降羹幸,騷人擱筆費(fèi)評(píng)章脊髓。梅須遜雪三分白,雪卻輸梅一段香睹欲。 今天畫(huà)的是雪梅 實(shí)在是喜愛(ài) 終于可以通過(guò)自己...
    虛空中的兔子閱讀 841評(píng)論 15 23
  • 你說(shuō)努力生活的意義到底是什么供炼?當(dāng)我十幾歲的時(shí)候我想要的生活是那種特別文藝女輕年的生活,可是在我邁進(jìn)了二十歲的門(mén)檻之...
    月光夕顏閱讀 206評(píng)論 4 2