I'm getting exception:
org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I have JPA entity
@Entity(name = "products")
class JpaProductEntity {
@Id
private ProductId id;
private String payload;
private Integer version;
public JpaProductEntity() {
}
public void setId(ProductId id) {
this.id = id;
}
public String getPayload() {
return payload;
}
public void setPayload(String payload) {
this.payload = payload;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
Id class
public class ProductId implements Serializable {
private static final long serialVersionUID = -6110163899364126142L;
private String identifier;
public ProductId(String identifier) {
this.identifier = identifier;
}
public static ProductId from(String identifier) {
Assert.notNull(identifier, "Identifier cannot be null");
return new ProductId(identifier);
}
public static ProductId generate() {
return new ProductId(Id.generateIdentifier());
}
}
Also, converter:
@Converter(autoApply = true)
public class ProductIdPostgresUuidConverter implements AttributeConverter<ProductId, UUID> {
@Override
public UUID convertToDatabaseColumn(ProductId attribute) {
return UUID.fromString(attribute.toString());
}
@Override
public ProductId convertToEntityAttribute(UUID dbData) {
return ProductId.from(dbData.toString());
}
}
It seems, converter does not work at all (I've put break points in converter methods, but nothing happens, debugger does not enter there).
ProductIdclass with@Embeddableand the id inJpaProductEntityas@Embedded. No conversion would be required then. Of courseProductIdwill need a getter and setter foridentifierand a no-argument constructor.