无法在休眠状态下更新数据类型byte []的列值

时间:2013-05-29 11:04:29

标签: spring hibernate annotations

我的用户身份验证表“AuthUser”如下所示:

  id bigint NOT NULL,
  username character varying(255) NOT NULL,
  password bytea[],
  salt bytea[]

POJO代表:

  ...
  private byte[]            password;

  private byte[]            salt;
  ... 
  getter setter methods

我使用以下查询将salt和加密密码更新为:

@Transactional(readOnly = false)
  public void updateSaltAndPasswordByUsername(String username, byte[] salt, byte[] password) {
    String hql = "UPDATE AuthUser SET password= ? , salt= ? WHERE username = ? ";
    sessionFactory.getCurrentSession().createQuery(hql).setBinary(0, password).setBinary(1, salt).setString(2, username).executeUpdate();
  }

但它给出了错误:

org.postgresql.util.PSQLException: ERROR: column "password" is of type bytea[] but expression is of type bytea
  Hint: You will need to rewrite or cast the expression.

我想在数据库的byte []中保存salt和密码。

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

尝试

  id bigint NOT NULL,
  username character varying(255) NOT NULL,
  password bytea,
  salt bytea

请注意,bytea[]等于bytea ARRAY,期望{byte[], byte[],...}类型的数据