hibernate注解大全

hibernate注解大全

ID:40492756

大?。?19.69 KB

頁數(shù):29頁

時間:2019-08-03

hibernate注解大全_第1頁
hibernate注解大全_第2頁
hibernate注解大全_第3頁
hibernate注解大全_第4頁
hibernate注解大全_第5頁
資源描述:

《hibernate注解大全》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在教育資源-天天文庫。

1、Hibernate注釋大全Documentfileandexample:Hibernate,JBossetc.?一、實體Bean每個持久化POJO類都是一個實體Bean,通過在類的定義中使用@Entity注解來進行聲明。聲明實體Bean@EntitypublicclassFlightimplementsSerializable{?Longid;?@Id?publicLonggetId(){returnid;}?publicvoidsetId(Longid){this.id=id;}}@Entity注解將一個類聲明為實體Bean,@Id注解聲明了該

2、實體Bean的標識屬性。Hibernate可以對類的屬性或者方法進行注解。屬性對應field類別,方法的getXxx()對應property類別。定義表通過@Table為實體Bean指定對應數(shù)據(jù)庫表,目錄和schema的名字。@Entity@Table(name="tbl_sky")publicclassSkyimplementsSerializable{...@Table注解包含一個schema和一個catelog屬性,使用@UniqueConstraints可以定義表的唯一約束。@Table(name="tbl_sky",?uniqueCon

3、straints={@UniqueConstraint(columnNames={"month","day"})})上述代碼在?"month"和"day"兩個field上加上uniqueconstrainst.@Version注解用于支持樂觀鎖版本控制。@EntitypublicclassFlightimplementsSerializable{??...??@Version??@Column(name="OPTLOCK")??publicIntegergetVersion(){...}}version屬性映射到"OPTLOCK"列,entity

4、manager使用這個字段來檢測沖突。一般可以用數(shù)字或者timestamp類型來支持version.實體Bean中所有非static非transient屬性都可以被持久化,除非用@Transient注解。默認情況下,所有屬性都用@Basic注解。publictransientintcounter;//transientpropertyprivateStringfirstname;//persistentproperty@TransientStringgetLengthInMeter(){...}//transientpropertyStringg

5、etName(){...}//persistentproperty@BasicintgetLength(){...}//persistentproperty@Basic(fetch=FetchType.LAZY)StringgetDetailedComment(){...}//persistentproperty@Temporal(TemporalType.TIME)java.util.DategetDepartureTime(){...}//persistentproperty@Enumerated(EnumType.STRING)Starre

6、dgetNote(){...}//enumpersistedasStringindatabase上述代碼中counter,lengthInMeter屬性將忽略不被持久化,而firstname,name,length被定義為可持久化和可獲取的。@TemporalType.(DATE,TIME,TIMESTAMP)分別Mapjava.sql.(Date,Time,Timestamp).@Lob注解屬性將被持久化為Blog或Clob類型。具體的java.sql.Clob,Character[],char[]?和java.lang.String?將被持久

7、化為Clob類型.java.sql.Blob,Byte[],byte[]?和serializabletype?將被持久化為Blob類型。@LobpublicStringgetFullText(){??returnfullText;?//clobtype}@Lobpublicbyte[]getFullCode(){?returnfullCode;?//blogtype}@Column注解將屬性映射到列。@EntitypublicclassFlightimplementsSerializable{??...??@Column(updatable=fa

8、lse,name="flight_name",nullable=false,length=50)??publicStringgetNam

當前文檔最多預覽五頁,下載文檔查看全文

此文檔下載收益歸作者所有

當前文檔最多預覽五頁,下載文檔查看全文
溫馨提示:
1. 部分包含數(shù)學公式或PPT動畫的文件,查看預覽時可能會顯示錯亂或異常,文件下載后無此問題,請放心下載。
2. 本文檔由用戶上傳,版權(quán)歸屬用戶,天天文庫負責整理代發(fā)布。如果您對本文檔版權(quán)有爭議請及時聯(lián)系客服。
3. 下載前請仔細閱讀文檔內(nèi)容,確認文檔內(nèi)容符合您的需求后進行下載,若出現(xiàn)內(nèi)容與標題不符可向本站投訴處理。
4. 下載文檔時可能由于網(wǎng)絡波動等原因無法下載或下載錯誤,付費完成后未能成功下載的用戶請聯(lián)系客服處理。