4

I was trying to insert a new data into both database server. This one works in Oracle 11g but does not work in PostgreSQL 9+. I cannot trace the issue as the error says:

column "BOOLEAN_VALUE" is of type numeric but expression is of type boolean Hint: You will need to rewrite or cast the expression.

The column is nullable and in codes below, we do not set any data.

Table Def:(Numeric)
"BOOLEAN_VALUE" NUMBER(1,0)

Domain:
@Column(name = "BOOLEAN_VALUE")
public Boolean getBooleanValue() {
    return booleanValue;
}

public void setBooleanValue(Boolean booleanValue) {
    this.booleanValue = booleanValue;
}

How data insertion:
MyData myData = new MyData();
myData.setMoneyValue("$ 120")
myServiceRepository.save(myData);

We did passing 0 or 1 as default value but none has worked. Hope someone can give me some light.

S-Man
  • 22,521
  • 7
  • 40
  • 63
Yejin
  • 541
  • 2
  • 15
  • 32

2 Answers2

1

PostgreSQL do not auto-cast int to boolean automatically, eventually you can create your own cast function.

See: https://www.postgresql.org/docs/9.4/static/sql-createcast.html

rbicchierai
  • 186
  • 2
  • 3
  • Thank you. The solution we did is we just changed the column definition from Numeric to Boolean type. – Yejin May 11 '18 at 06:00
0

For hibernate 6 you can annotate the jdbc type to integer

@JdbcTypeCode(Types.INTEGER)

private boolean booleanColumn;

Marc Magon
  • 713
  • 7
  • 11