DB2 + JPA抛出一个错误:在表中找不到列 [英] DB2 + JPA throwing an error: column not found in the table

查看:428
本文介绍了DB2 + JPA抛出一个错误:在表中找不到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当JPA尝试持久化一个实体时,DB2-express会抛出一个似乎不可能的错误:

The DB2-express is throwing an error that seems impossible, when JPA tries to persist an entity:

ReportingSQLException: "ITEMID" is not valid in the context where it is used..

INSERT INTO NULLID."DynamicDatabaseTable" ("colname", "rownumber", "value")
VALUES (?, ?, ?) [params=?, ?, ?]

由于ITEMID未被使用在上面的查询中,这个错误怎么样? ITEMID是一个自动身份生成的列。

Since ITEMID is not used in the query above, how can this error be? The ITEMID is an auto-identity-generated column.

我已经尝试手动执行查询,工作OK,所以任何人都知道什么是什么?即使经过很多谷歌搜索,我在这里完全无知。

I have tried executing manually the query and it works OK, so anybody know what's all about? Even after lot of googling, I'm totally clueless here.

DB2中的数据库表很好,我有三重检查:

The database table in DB2 is fine, I have triple check:

"itemid" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH 1...), 
"rownumber" BIGINT NOT NULL, 
"colname" CHAR(30 OCTETS) NOT NULL, 
"value" VARCHAR(254 OCTETS)






我已经通过使用Eclipse向导创建了一个简单的javaJPA Entity from a table我已经三重检查了这个类是否正常。


I had created a simple java "JPA Entity from a table", by using the Eclipse wizard, and I've triple check the class is fine.

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="\"itemid\"", unique=true, nullable=false)
private long itemid;

@Column(name="\"rownumber\"", nullable=false)
private long rownumber;

@Column(name="\"colname\"", nullable=false, length=30)
private String colname;

@Column(name="\"value\"", length=254)
private String value;

我也重新启动了整个电脑,以防万一,但没有...而我正在使用最近的版本,几周前安装了几个。

I have also restarted the whole computer just in case, but nothing... And I'm using most recent versions, clean installed couple of weeks ago.

推荐答案

itemid不等于 itemid - SQL标识符默认情况下转换为大写,如果不包含双引号。根据您的DDL,您创建了具有小写列名称的表。显然,JPA不能正常处理,生成的代码中的某个地方使用unquoted itemid ,它被转换为大写字母,毫不奇怪,在表中找不到列

"itemid" is not equal itemid -- SQL identifiers are by default converted to upper case if not enclosed in double quotation marks. According to your DDL you created the table with lowercase column names. Apparently, JPA does not handle that properly and somewhere in the generated code uses unquoted itemid, which gets converted to upper case and, not surprisingly, the column cannot be found in the table.

没有理由在SQL中使用区分大小写的标识符,所以我建议您不要这样做,以避免这些问题。

There is no reason to use case sensitive identifiers in SQL, so I suggest you don't do that to avoid these kinds of problems.

这篇关于DB2 + JPA抛出一个错误:在表中找不到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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