为什么Hibernate会忽略@Column注解的name属性?
使用Hibernate 3.3.1和Hibernate Annotations 3.4,数据库是DB2/400 V6R1,在WebSphere 7.0.0.9上运行它
我有以下类
@Entity
public class Ciinvhd implements Serializable {
@Id
private String ihinse;
@Id
@Column(name="IHINV#")
private BigDecimal ihinv;
....
}
出于我无法理解的原因,Hibernate忽略指定的列名并使用'ihinv'来生成 SQL:
select
ciinvhd0_.ihinse as ihinse13_,
ciinvhd0_.ihinv as ihinv13_,
...
这当然会给我以下错误:
Column IHINV not in table CIINVHD
编辑: 我将 hibernate 的日志级别切换为 DEBUG,并且我看到它不处理该字段的列注释。尝试了一些随机的事情,但它不起作用。
以前有人遇到过这个问题吗?我有其他实体,它们在数据库字段名称中使用 # 的方式非常相似,并且它们是 PK 的一部分,我对它们没有这个问题。
Using Hibernate 3.3.1 and Hibernate Annotations 3.4, the database is DB2/400 V6R1, running that on WebSphere 7.0.0.9
I have the following class
@Entity
public class Ciinvhd implements Serializable {
@Id
private String ihinse;
@Id
@Column(name="IHINV#")
private BigDecimal ihinv;
....
}
For reasons I can't figure, Hibernate ignores the specified column name and uses 'ihinv' to generate the SQL:
select
ciinvhd0_.ihinse as ihinse13_,
ciinvhd0_.ihinv as ihinv13_,
...
Which of course gives me the following error:
Column IHINV not in table CIINVHD
Edit: I switched the log level of hibernate to DEBUG, and I see that it does not process the column annotation for that field. Tried several random things it just doesn't work.
Did anyone had this problem before? I have other entities that are very alike in the way that they are using # in their database field names and that are part of the PK and I don't have this problem with them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试某种引用:
例如:
或
另一种选择是深入研究源代码 DB2 的 Hibernate 方言 并查看它是否包含任何有用的内容。
当然,最简单的方法是如果可能的话从列名中删除哈希。
You could try some kind of quoting:
For example:
or
Another option would be to dig in to source code Hibernate dialect for DB2 and see if it contains anything helpful.
Of course, the easiest way would be to remove the hash from column name if possible.
我怀疑问题出在列名中的哈希值上。 hibernate 论坛上的类似问题建议反引号在这里很有用。
I suspect that the problem is the hash in the column name. A similar question on the hibernate forums suggests that backticks can be useful here.