Postgresql UUID supported by Hibernate?

前端 未结 5 1384
悲哀的现实
悲哀的现实 2020-11-27 07:28

I can\'t get Hibernate working with java.util.UUID for PostgreSQL.

Here is the mapping using javax.persistence.* annotations:

private UUID itemUuid;
         


        
5条回答
  •  臣服心动
    2020-11-27 08:04

    Now you can also use the UUID class provided by java.util.UUID which gets mapped to uuid datatype of Postgres by Hibernate without any conversions required while reading/writing from the database.

      @Id
      @GeneratedValue
      private UUID id;
    

    The generated value is auto by default this lets your JVM define the UUID. This also allows hibernate to use the batch insert optimisation.

    You can configure the database to set the UUID value. More information can be found here https://vladmihalcea.com/uuid-identifier-jpa-hibernate/

提交回复
热议问题