ID Generation:
ID generator visible code not available within hibernate
Using @generatedvalue
1 can be used at the same time for different databases
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
2 for MySQL
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
3 for Oracle
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="s_gen")
@SequenceGenerator(name="s_gen",sequenceName="s_seq")
Description: The Strategy property of @GeneratedValue () supports the ID generator in 5: In addition to the above 3 Chinese and foreign generationtype.table
2 with the use of @genericgenerator not used alone
ID generator visible code not available within hibernate
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 );
)
If you want different tables to use the same primary key generator, you can set the Name property of his generator to the same
For example:
@GeneratedValue(name="id1")
@GenericGenerator(name="id1",strategy="identity")