org.postgresql.util.PSQLException:错误:列“ deleted”的类型为smallint,但表达式的类型为boolean

时间:2019-11-26 06:31:31

标签: postgresql java-8 liquibase

我正在尝试使用以下配置在postrges数据库中将布尔值分别保存为0和false,以及1和true,

liquibase \ changes \ 001.add-delete-column.json

 {
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "001-add-delete-colum",
        "author": "equity-deal",
        "changes": [
          {
            "addColumn": {
              "tableName": "TABLE_NAME",
              "columns": [
                {
                  "column": {
                    "name": "DELETED",
                    "type": "SMALLINT",
                    "constraints": {
                      "nullable": false
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

我的域对象是boolean类型,但我将json定义为BIGINT的值。理想情况下,对于已定义域对象的错误/真实条件,我期望将值存储为0或1。

域对象

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ExampleClass {

    private Long id;

    private boolean deleted;
}

当执行上面的代码并以下面的异常结束时

org.postgresql.util.PSQLException: ERROR: column "deleted" is of type smallint but expression is of type boolean
  Hint: You will need to rewrite or cast the expression.
  Position: 159
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
    at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:120)

如何实现将0或1保存为false或true?

0 个答案:

没有答案