FindByUUID() using Spring Data's JPA Repository

前端 未结 4 502
面向向阳花
面向向阳花 2020-12-21 15:39

for some reason I have not being able to find a suitable answer for this. I have the following simple entity:

@Entity
@Table(name = \"simple_entity\")
@Acce         


        
相关标签:
4条回答
  • 2020-12-21 16:17

    I tackled the same question recently, and if someone stumbles up here, the solution for me was to annotate the column with

    @Column(name = "id", columnDefinition = "BINARY(16)")
    private UUID id;
    

    which solved the problem for me.

    0 讨论(0)
  • 2020-12-21 16:21

    Change binary column to String. Default is binary you must add this addnotation

    @Type(type="org.hibernate.type.UUIDCharType")
    
    0 讨论(0)
  • 2020-12-21 16:30

    Had the same problem, specifically it works in H2 but not in MySQL.

    In addition I got PRIMARY key constraint failures attempting to update the record because Hibernate (under JPA) was querying to see if the record exists and it did not find it.

    Using @Column(length=16) also solves this problem neatly, assuming MySQL is using a BINARY column... otherwise the matching will fail due to the column having extra data in the DB (I think it defaults to BINARY[32]).

    0 讨论(0)
  • 2020-12-21 16:39

    Try annotate your UUID property with @org.hibernate.annotations.Type(type="org.hibernate.type.UUIDCharType")
    or
    @org.hibernate.annotations.Type(type="org.hibernate.type.UUIDBinaryType")

    I faced a problem similar while query database with UUID due to MSB/LSB swap with UUID in binary format; we solved the problem treating data as String and do necessary conversion before conversion.

    0 讨论(0)
提交回复
热议问题