【问题标题】:How to insert a Set into a column of type integer[]?如何将 Set 插入整数 [] 类型的列中?
【发布时间】:2013-07-25 05:59:47
【问题描述】:

我有一个integer[] 类型的列,使用以下查询创建。

...
questions int[] DEFAULT '{}',
...

我正在尝试使用 Hibernate 的查询功能插入一组整数。

Set<Integer> questions = randomQuestions();
Query query = session.createSQLQuery("UPDATE contestant SET questions=:questions WHERE email=:email");
query.setParameterList("questions", questions);
query.setParameter("email", email);
query.executeUpdate();

这没有成功执行并抛出异常。

Caused by: org.postgresql.util.PSQLException: ERROR: column "questions" is of type integer[] but expression is of type record
Hint: You will need to rewrite or cast the expression.

我将如何将我的整数集插入数据库?

【问题讨论】:

    标签: java sql hibernate postgresql


    【解决方案1】:
    query.setParameterList("questions", questions.toArray(new Integer[]));
    

    试试上面的,应该可以的。(虽然没试过)

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多