How to map Postgres _INT8 to a Java object using Hibernate?

There is a table created with SQL DDL script that has a column of type _INT8 . If I try to match it with long (which is Postgres INT8 ), it throws it 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) 

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

How will Postgres' _INT8 map to a Java type using Hibernate?

+1
source share
1 answer

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

I have no idea why the underscore prefix is ​​used, this is terrible, but it really should be visible only inside the server, so I'm surprised that you see it appearing in messages. Take this, for example, where the server shows bigint[] as the column type in the messages:

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

If you want to match it in Hibernate, you must match it as long[] , if Hibernate even supports SQL arrays - which do not appear in . You will probably have to add your own UserType implementation, which uses JDBC support for SQL arrays . Another example on the Hibernate forums . This is similar to frequently asked questions , but, like most things in Hibernate / JPA, you will find that as soon as you try to use nothing but the most basic database functions, you will bang your head against a brick wall.

+3
source

Source: https://habr.com/ru/post/1208051/


All Articles