2

We have a use case where there exists a column 'datewise_tariff' of type numeric(13,3)[] in Postgres database. Values stored with this column are decimal values like {953.893,953.893,953.893}

We need to map this column type to a Hibernate Java Entity but we are getting the below error:

SQL Error: 0, SQLState: 42804
ERROR: column "datewise_tariff" is of type numeric[] but expression is of type bytea
  Hint: You will need to rewrite or cast the expression.
  Position: 738

We tried mapping it via:

@Column(name = "datewise_tariff")
private float[] datewiseTariff
@Column(name = "datewise_tariff")
private BigDecimal[] datewiseTariff
@Column(name = "datewise_tariff", columnDefinition = "numeric(13,3)[]")
private float[] datewiseTariff;
@Column(name = "datewise_tariff", columnDefinition = "numeric(13,3)[]")
private BigDecimal[] datewiseTariff;
@Column(name = "datewise_tariff", columnDefinition = "numeric(13,3)[]")
private byte[] datewiseTariff;
@Column(name = "datewise_tariff")
private byte[] datewiseTariff;

All above methods seems to be not working and always throws the same above error. Also, tried using hibernate-types sdk but it seems that it also doesn't have support for the same.

1 Answer 1

3

After an unending era of hit and trial and diving into the ocean of Hibernate documentation, Finally, found a way to do it. @ColumnTransformer came to the rescue.

Usage as follows:

@Type(type = "list-array")
@Column(name = "datewise_tariff")
@ColumnTransformer(write = "?::numeric(13,3)[]", read = "?::float[]")
private List<Double> datewiseTariff;

list-array is defined using hibernate-types library.

@TypeDef(name = "list-array", typeClass = ListArrayType.class)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.