Created
November 5, 2015 08:13
-
-
Save dungdm93/e9a45cfbc1eb16290ddb to your computer and use it in GitHub Desktop.
[Java][JPA][Hibernate] UUID & Hibernate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Employee extends AbstractBaseEntity { | |
// Approach 1: | |
// @Id | |
// public String id; | |
// Approach 2: | |
@Id | |
// default column type is byte array | |
@Type(type = "org.hibernate.type.PostgresUUIDType") // or type = "pg-uuid" | |
@GeneratedValue(generator = "uuid") | |
@GenericGenerator( | |
name = "uuid", | |
strategy = "org.hibernate.id.UUIDGenerator", | |
parameters = { | |
@Parameter( | |
name = "uuid_gen_strategy_class", | |
value = "org.hibernate.id.uuid.CustomVersionOneStrategy" | |
) | |
} | |
) | |
public UUID id; | |
public AbstractBaseEntity() { | |
// Approach 1: | |
// this.id = UUID.randomUUID().toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment