JPA 註解的幾個要點

2021-05-26 23:18:41 字數 1112 閱讀 2651

1.設定pojo為實體 

@entity

//標識這個pojo是乙個jpa實體 public class users implements serializable 2.設定表名 @entity @table (name= users ) //指定表名為users public class users implements serializable 3.設定主鍵 public 

jpa 註解的幾個要點  

1.設定pojo為實體  

@entity

//標識這個pojo是乙個jpa實體     

public

class

users 

implements

serializable       

2.設定表名  

@entity

@table

(name = 

"users"

) //指定表名為users     

public

class

users 

implements

serializable       

3.設定主鍵  

public

class

users 

implements

serializable       

6.主鍵生成策略  

public

class

users 

implements

serializable , inversejoincolumns = )       

private

collectionmanybidcollection;       

第二個pojo  

@entity

@table

(name = 

"t_manyb"

)       

public

class

manyb 

implements

serializable        

public

void

settempvalue(

intvalue)   

JPA註解補充

fetchtype.lazy和 fetchtype.eager 什麼區別?1 fetchtype.lazy 懶載入,載入乙個實體時,定義懶載入的屬性不會馬上從資料庫中載入。2 fetchtype.eager 急載入,載入乙個實體時,定義急載入的屬性會立即從資料庫中載入。3 比方 user 類有兩個屬...

JPA註解查詢

1 entity name entityname 必須,name為可選,對應資料庫中一的個表 entity 標識這個pojo是乙個jpa實體 public class users implements serializable 2 table name catalog schema 可選,通常和 e...

JPA實體註解

entity name entityname 必須,name為可選,對應資料庫中一的個表 table name catalog schema 可選,通常和 entity配合使用,只能標註在實體的class定義處,表示實體對應的資料庫表的資訊 name 可選,表示表的名稱。預設地,表名和實體名稱一致,...