hibernate annoation (三 id生成器)
当前位置:以往代写 > JAVA 教程 >hibernate annoation (三 id生成器)
2019-06-14

hibernate annoation (三 id生成器)

hibernate annoation (三 id生成器)

id生成:

hibernate内不行利用的id生成器可见代码

利用@GeneratedValue

1 正对差异的数据库可以同时利用

  @Id
    @GeneratedValue(strategy = GenerationType.AUTO)

2 针对mysql

 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)

3 针对oracle

  @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE,generator="s_gen")
    @SequenceGenerator(name="s_gen",sequenceName="s_seq")

说明:@GeneratedValue()的strategy属性支持5中id生成器:除上面3中外尚有GenerationType.TABLE

2共同利用@GenericGenerator 不光独利用

hibernate内不行利用的id生成器可见代码

GENERATORS.put( "uuid", UUIDHexGenerator.class );
 GENERATORS.put( "hilo", TableHiLoGenerator.class );
 GENERATORS.put( "assigned", Assigned.class );
 GENERATORS.put( "identity", IdentityGenerator.class );
 GENERATORS.put( "select", SelectGenerator.class );
 GENERATORS.put( "sequence", SequenceGenerator.class );
 GENERATORS.put( "seqhilo", SequenceHiLoGenerator.class );
 GENERATORS.put( "increment", IncrementGenerator.class );
 GENERATORS.put( "foreign", ForeignGenerator.class );
 GENERATORS.put( "guid", GUIDGenerator.class );
 GENERATORS.put( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
 GENERATORS.put( "sequence-identity", SequenceIdentityGenerator.class );
)

假如想要差异的表利用沟通的主键生成器,可以把他的generator的name属性设为沟通即可

譬喻:

@GeneratedValue(name="id1")
@GenericGenerator(name="id1",strategy="identity")

    关键字:

在线提交作业