m3t*_*man 2 java postgresql orm hibernate jpa
有一个使用 SQL DDL 脚本创建的表,其中有一列类型为_INT8。如果我尝试将它映射到long(即 Postgres INT8),它会在堆栈的末尾抛出。
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)
Run Code Online (Sandbox Code Playgroud)
如果我尝试将它映射到long[](或任何其他数组类型)而不是Found: _int8, expected: bytea
如何_INT8使用 Hibernate 将Postgres映射到 Java 类型?
_int8是 type 的内部别名int8[],即长整数数组。
我不知道为什么使用下划线前缀,这太可怕了,但它应该只在服务器内部可见,所以我很惊讶你看到它出现在消息中。以此为例,服务器bigint[]在消息中显示为列类型:
http://sqlfiddle.com/#!12/61bc5/1
如果你想在 Hibernate 中映射它,你必须将它映射为long[],如果 Hibernate 甚至支持 SQL 数组 -它似乎没有。您可能必须添加自己的 UserType 实现,该实现使用对 SQL 数组的 JDBC 支持。Hibernate 论坛上的另一个例子。这似乎是一个常见问题解答,但与 Hibernate/JPA 中的大多数内容一样,您会发现,一旦您尝试使用除最基本的数据库功能以外的任何内容,您就会将头撞在砖墙上。
| 归档时间: |
|
| 查看次数: |
3410 次 |
| 最近记录: |