Skip to content

Instantly share code, notes, and snippets.

@dungdm93
Created November 5, 2015 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dungdm93/e9a45cfbc1eb16290ddb to your computer and use it in GitHub Desktop.
Save dungdm93/e9a45cfbc1eb16290ddb to your computer and use it in GitHub Desktop.
[Java][JPA][Hibernate] UUID & Hibernate
@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