PSQLException: ERROR: operator does not exist: character varying = uuid

PSQLException: ERROR: operator does not exist: character varying = uuid

我有这个存储库:

@Repository
public interface DomainRepository extends CrudRepository<Domain, String> {
    Domain findByUuid(UUID uuid);
}

我有这个实体:

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name="a", schema="b")
public class Domain {
    @Id
    private String id;
    private UUID uuid;

}

但是当我这样做的时候 Domain d = domainRepository.findByUuid(UUID.randomUUID());

我得到 PSQLException: ERROR: operator does not exist: character varying = uuid(table 中的列类型是 VARCHAR)。

如何解决这个问题?

尝试将字段的类型定义为 Hibernate 无法通过使用 @Type(type="org.hibernate.type.UUIDCharType")

注释字段来理解该类型
@Type(type="org.hibernate.type.UUIDCharType")
private UUID id;