首页  

hibernate5 主键生成策略     所属分类 hibernate 浏览量 585
increment   首先获取该表中最大主键值,然后加一插入 
identity    使用数据库自增
sequence    
native      根据数据库 从 identity sequence 中选择一种
assigned    手工指定
uuid        32位字符串


@GeneratedValue 指定主键生成策略 @GenericGenerator 自定义主键生成策略 @GeneratedValue generator属性引用 @GenericGenerator定义的主键生成策略器的name值,strategy指定生成策略 @Id @GeneratedValue(generator="increment") @GenericGenerator(name="increment", strategy = "increment") public Long getId() { return id; } <class name="Event" table="EVENTS"> <id name="id" column="EVENT_ID"> <generator class="increment"/> </id> <property name="date" type="timestamp" column="EVENT_DATE"/> <property name="title"/> </class> @GeneratedValue(generator="increment") @GenericGenerator(name="increment", strategy = "increment") @GeneratedValue(generator="identity") @GenericGenerator(name="identity", strategy = "identity") @GeneratedValue(generator="native") @GenericGenerator(name="native", strategy = "native") @GeneratedValue(generator="sequence") @GenericGenerator(name="sequence", strategy = "sequence") hibernate5.3.28 org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory public DefaultIdentifierGeneratorFactory() { register( "uuid2", UUIDGenerator.class ); register( "guid", GUIDGenerator.class ); // can be done with UUIDGenerator + strategy register( "uuid", UUIDHexGenerator.class ); // "deprecated" for new use register( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated register( "assigned", Assigned.class ); register( "identity", IdentityGenerator.class ); register( "select", SelectGenerator.class ); register( "sequence", SequenceStyleGenerator.class ); register( "seqhilo", SequenceHiLoGenerator.class ); register( "increment", IncrementGenerator.class ); register( "foreign", ForeignGenerator.class ); register( "sequence-identity", SequenceIdentityGenerator.class ); register( "enhanced-sequence", SequenceStyleGenerator.class ); register( "enhanced-table", TableGenerator.class ); }

上一篇     下一篇
Java Files 常用方法

hibernate Session get()和load()方法区别

hibernate5.3 tutorials

windows使用技巧

Java identityHashCode

dubbo简史