hibernate加jpa自帶一共14種。
1.native
@id
@generatedvalue(generator = "gen")
@genericgenerator(name = "gen", strategy = "native")
或
@id
@generatedvalue(strategy=generationtype.auto)
2.table : org.hibernate.id.enhanced.tablegenerator
@id
@generatedvalue(strategy=generationtype.table, generator="empgen")
@tablegenerator(
name="empgen",
table="id_gen",
pkcolumnname="gen_key",
valuecolumnname="gen_value",
pkcolumnvalue="emp_id",
allocationsize=1)
public int id;
3.uuid : org.hibernate.id.uuidhexgenerator
最高生成36位長唯一字串(加上分隔符),預設32位
@id
@generatedvalue(generator = "gen")
@genericgenerator(
name = "gen",
strategy = "uuid",
parameters=)
private string id;
4.hilo : org.hibernate.id.tablehilogenerator
@id
@generatedvalue(generator="gen")
@genericgenerator(
name="gen",
strategy="hilo",
parameters=)
private int id;
注釋部分可以做相應的修改
5.assigned : org.hibernate.id.assigned
@id
private int id;
6.identity : org.hibernate.id.identitygenerator
@id
@generatedvalue(strategy=generationtype.identity)
private int id;
7.select : org.hibernate.id.selectgenerator
8.sequence : org.hibernate.id.sequencegenerator
@id
@generatedvalue(generator="gen")
@genericgenerator(
name="gen",
strategy="sequence",
parameters=)
private int id;
或
@id
@generatedvalue(strategy=generationtype.sequence)
private int id;
支援db2.h2.hsql.informix.ingres.interbase.mckoi.mimer.oracle.postgre.rdmsos2200.sapdb.timesten
9.seqhilo : org.hibernate.id.sequencehilogenerator
@id
@generatedvalue(generator="gen")
@genericgenerator(
name="gen",
strategy="seqhilo",
parameters=)
private int id;
支援db2.h2.hsql.informix.ingres.interbase.mckoi.mimer.oracle.postgre.rdmsos2200.sapdb.timesten
10.increment : org.hibernate.id.incrementgenerator
@entity
@table(name = "id_increment_gen")
public class incrementgen )
private int id;
其中tables引數和identity_tables引數互斥,tables引數優先。column引數和target_column引數互斥, column引數優先,支援多表,以","分隔,會生成類似如下的語句:
select max (ids_.id) from ( select id from id_increment_gen ) ids_
多表時為:select max (ids_.id) from ( select id from id_increment_gen1 union select id from id_increment_gen2 ) ids_
11.foreign : org.hibernate.id. foreigngenerator
12.guid : org.hibernate.id. guidgenerator
@id
@generatedvalue(generator = "gen")
@genericgenerator(name = "gen", strategy = "guid")
private string id;
支援mysql,oracle,sybase
13.uuid.hex : org.hibernate.id.uuidhexgenerator // uuid.hex is deprecated
14.sequence-identity : org.hibernate.id.sequenceidentitygenerator
15.自定義
可同時實現介面org.hibernate.id.identifiergenerator
,org.hibernate.id.configurable
@id
@generatedvalue(generator = "gen")
@genericgenerator(name = "gen", strategy = "xg.custgenerator")
private string id;
strategy填寫具體類名
jpa hibernate分頁查詢
工具類pageutils 當前頁 private int currentpage 每頁資料條數 private int pagesize 經銷商 private dealer dealer 貸款 private loan loan 起始時間 private date starttime 終止時間 p...
jpa hibernate延遲問題解決
如果出現org.hibernate.lazyinitializationexception異常,no session orsession is closed,那是因為你使用了jpa或者hibernate的延時載入方法,並在訪問物件的時候,session已經關閉。方式一 在 web.xml中新增fil...
sql 設定主鍵 聯合主鍵
alter table yourtable add constaintname primary key columnname constaintname 資料型別 yourtable 表名 columnname 列名 or create table yourtable column1 int pri...