如何使用Hibernate将Postgres _INT8映射到Java实体? [英] How to map Postgres _INT8 to Java entity using Hibernate?

查看:139
本文介绍了如何使用Hibernate将Postgres _INT8映射到Java实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个使用SQL DDL脚本创建的表,其中有一个 _INT8 类型的列。如果我试图将它映射到 long (它是Postgres INT8 ),它会在堆栈的末尾抛出。 / p>

There is a table created with an SQL DDL script which has a column of type _INT8. If I try to map it to long (which is Postgres INT8) it throws at the end of the stack.

Caused by: org.hibernate.HibernateException: Wrong column type in [schme_name].[table_name] for column [column_name]. Found: _int8, expected: int8
    at org.hibernate.mapping.Table.validateColumns(Table.java:373)
    at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1265)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:508)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)

如果我试图将它映射到 long [] (或任何其他数组类型)而不是 Found:_int8,expected:bytea

If I try to map it to long[] (or any other array type) instead of Found: _int8, expected: bytea

使用Hibernate如何将Postgres的 _INT8 映射到Java类型中?

How can Postgres' _INT8 be mapped into a Java Type using Hibernate?

推荐答案

_int8 是一个in int8 [] 类型的外部别名,即一个长整数数组。

_int8 is an internal alias for the type int8[], ie an array of long integers.

我不知道为什么下划线前缀被使用,这是可怕的,但它应该只在服务器内部可见,所以我很惊讶你看到它出现在消息中。以服务器显示 bigint [] 作为消息中的列类型:

I have no idea why the underscore prefix is used, it's horrible, but it should really only be visible inside the server so I'm surprised you're seeing it come up in messages. Take this, for example, where the server shows bigint[] as the column type in messages:

http://sqlfiddle.com/#!12/61bc5/1

如果你想在Hibernate中映射它,如果Hibernate甚至支持SQL数组,你必须将它映射为 long [] - <一个href =https://stackoverflow.com/a/1647660/398670>它似乎没有。您可能必须添加您自己的UserType实施,该实施使用JDBC支持SQL阵列 Hibernate论坛上的另一个例子。它似乎有点常见问题,但像Hibernate / JPA中的大部分内容都会发现,只要尝试使用除最基本的数据库特性以外的任何内容,就会将您的头撞向砖墙。

If you want to map it in Hibernate, you must map it as a long[], if Hibernate even supports SQL arrays - which it does not appear to. You'll probably have to add your own UserType implementation that uses the JDBC support for SQL arrays. Another example on the Hibernate forums. It seems to be a bit of an FAQ, but like most things in Hibernate/JPA you'll find that as soon as you try to use anything but the most basic database features you'll be banging your head against a brick wall.

这篇关于如何使用Hibernate将Postgres _INT8映射到Java实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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