开发者

Why Hibernates ignores the name attribute of the @Column annotation?

开发者 https://www.devze.com 2022-12-28 00:35 出处:网络
Using Hibernate 3.3.1 and Hibernate Annota开发者_StackOverflow社区tions 3.4, the database is DB2/400 V6R1, running that on WebSphere 7.0.0.9

Using Hibernate 3.3.1 and Hibernate Annota开发者_StackOverflow社区tions 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.


You could try some kind of quoting:

For example:

@Column(name="`IHINV#`")

or

@Column(name="'IHINV#'")

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消