views:

79

answers:

2

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.

A: 

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.

jsight
This adresses the issue when you switch to a dialect that does not support the hash symbol. The hash symbol is used in many other tables in my database and I never got any issues. It is really with this table that I am having trouble. I might be facing a bug in hibernate. Thank you for helping.
svachon
@svachon - Are the other fields with hashes in them of the same type (ie, BigDecimal)? Perhaps you're hitting a bug in hibernate specific to its handling of that type?
jsight
@jsight - Yes there are other fields with hashes typed as BigDecimal. And I do have other working entities that have hash and BigDecimal.
svachon
@svachon - Perhaps check to make sure that the @Column import is actually the same? Perhaps one of them is coming from a different package? That seems unlikely, but the rest of the problem is ruling out a lot of more likely possibilities.
jsight
@jsight - Yes the import is the same. I guess I will have to create views with column names without the hash sign.
svachon
+2  A: 

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.

Juha Syrjälä
Thanks for the suggestion but that is not working for me.
svachon