This error still exists in Hibernate 4.
Test case table: Persian Devicement columns WRAR Lumbar, Directory, Persian (data types are unimportant here)
my mappings within my model are annotation based and for the two in question see the code snippet below:
For the table mapping:
@Entity @Table(name = "Persian Devicement", schema="dbo", catalog="MyDB") public class PersianDevicement implements Serializable {...
and I'm including the column name that has a space in it as well to surface what may be a separate issues:
@Id @Column(name="[WRAR Lumbar]", columnDefinition = "SMALLINT") public Integer getWrarLumbar() { return wrarLumbar; }
HERE IS THE HQL
FROM VersionEntitlement PersianDevicement ORDER BY wrarLumbar
HERE IS THE SQL GENERATED BY THE HQL/SQL TRANSLATOR:
select persiandev0_.[WRAR Lumbar] as WRAR1_5_, persiandev0_.Directory as Director2_5_, persiandev0_.Persian as Persian3_5_ from MyDB.dbo.Persian Devicement persiandev0_ order by persiandev0_.[WRAR Lumbar]
HERE IS WHAT WORKS:
select persiandev0_.[WRAR Lumbar] as WRAR1_5_, persiandev0_.Directory as Director2_5_, persiandev0_.Persian as Persian3_5_ from MyDB.dbo.[Persian Devicement] persiandev0_ order by persiandev0_.[WRAR Lumbar]
The only difference is the brackets around the Table Name [Persian Devicement]
From stepping through the code the failure seems to be occuring at
// PHASE 3 : Generate the SQL. generate( ( QueryNode ) sqlAst ); queryLoader = new QueryLoader( this, factory, w.getSelectClause() );
I didn't drill down into that first line to further pinpoint the problem but it should be pretty easy to locate and fix
two observations:
1. Why do I have to go further than name="WRAR Lumbar" @Column annotation to indicate there is a space in the column name. I had to manually add mssql proprietary brackets to indicate the column name had a space (name="[WRAR Lumbar]"). Before I did this the final generated sql was failing by the as: select persiandev0_.WRAR Lumbar as WRAR1_5_, persiandev0_.Directory as Director2_5_, persiandev0_.Persian as Persian3_5_ from MyDB.dbo.Persian Devicement persiandev0_ order by persiandev0_.WRAR Lumbar This is failure because I am having to use the brackets to trick HQL into rendering the MSSQL correctly instead of it knowing.
2. Why can I not do this hack with the Table name? When I changed the table annotation to be name = "[Persian Devicement]" I got the error code failed org.hibernate.HibernateException: Missing table: [Persian Devicement]
|