使用Hibernate映射boolean [] PostgreSql列 [英] Mapping a boolean[] PostgreSql column with Hibernate

查看:80
本文介绍了使用Hibernate映射boolean [] PostgreSql列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PostgreSql数据库中有一列,其类型定义为 boolean [] 。我希望使用Hibernate 3.3.x将其映射到Java实体属性。但是,我找不到适合Hibernate映射到的Java类型。我以为 java.lang.Boolean [] 是显而易见的选择,但是Hibernate抱怨:

I have a column in a PostgreSql database that is defined with type boolean[]. I wish to map this to a Java entity property using Hibernate 3.3.x. However, I cannot find a suitable Java type that Hibernate is happy to map to. I thought that the java.lang.Boolean[] would be the obvious choice, but Hibernate complains:

Caused by: org.hibernate.HibernateException:
    Wrong column type in schema.table for column mycolumn. Found: _bool, expected: bytea
    at org.hibernate.mapping.Table.validateColumns(Table.java:284)
    at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1130)

我也尝试了以下物业类型,但没有成功:

I have also tried the following property types without success:


  • java.lang.String

  • java.lang。 boolean []

  • java.lang.Byte []

  • java.lang.String
  • java.lang.boolean[]
  • java.lang.Byte[]

如何映射此列?

推荐答案

您需要实现您自己的UserType。 文章非常方便。我之所以加入此链接,是因为原始文章中的链接已断开。

You need to implement your own UserType. This article is very handy. I am including this link because the link in the original article is broken.

您可以通过覆盖一些打开来源UserTypes

这篇关于使用Hibernate映射boolean [] PostgreSql列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆