相关疑难解决方法(0)

使用Hibernate映射PostgreSQL数组

有没有人通过Hibernate成功地将PostgreSQL中的数值数组映射到java中的数值数组?

SQL:

CREATE TABLE sal_emp (name text, pay_by_quarter integer[]);
INSERT INTO sal_emp VALUES ('one', '{1,2,3}');
INSERT INTO sal_emp VALUES ('two', '{4,5,6}');
INSERT INTO sal_emp VALUES ('three', '{2,4,6}');
Run Code Online (Sandbox Code Playgroud)

制图:

<hibernate-mapping>
    <class name="SalEmp" table="sal_emp">
        <id name="name" />
        <property name="payByQuarter" column="pay_by_quarter" />
    </class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)

类:

public class SalEmp implements Serializable{
    private String name;
    private Integer[] payByQuarter;
    ...// getters & setters
}
Run Code Online (Sandbox Code Playgroud)

查询表格时出现异常.

java arrays postgresql hibernate

41
推荐指数
5
解决办法
4万
查看次数

"table"中列"xy"的列类型错误找到:int8,expected:int4

我正在使用postgres/postgis进行休眠.当我从"update"切换Hibernate属性"hibernate.hbm2ddl.auto"以验证我得到了这个异常:

引起:org.hibernate.HibernateException:列type_id的历史记录中的列类型错误.找到:int8,预期:int4

首先我认为hibernate需要对另一个表的每个引用都是int8.我选择将列type_id更改为bigint但没有成功.我没有想法.有人可以帮忙吗?

我的实体以这种方式构建:

@Entity
public class History{       
  @Id
  protected Integer id;
  private Date created_on;
  private Date timestamp;
  @ManyToOne
  private DataType type;
  private Double value;
}
@Entity
public class DataType{      
   @Id
   private Integer id;
   private String cname;
   private Date created_on;
   private String cunit;
 }
Run Code Online (Sandbox Code Playgroud)

这些是db中的表定义:

历史

    Column |            Type             | Modifiers                            
------------+-----------------------------+-----------------
id         | integer                     | not null default                          nextval('history_id_seq'::regclass)
created_on | timestamp without time zone | 
timestamp  | timestamp without time zone | 
value      | double precision            | 
type_id …
Run Code Online (Sandbox Code Playgroud)

java postgresql hibernate

5
推荐指数
0
解决办法
5687
查看次数

标签 统计

hibernate ×2

java ×2

postgresql ×2

arrays ×1