Hi,
The legacy MS SQL database I'm using has column names with all sorts of punctuation (even %). When I used hbm2java and Middlegen they seem to handle the punctuation by enclosing the field names in square brackets.
When I try to run a HQL query the SQL generated by Hibernate is not valid for MS SQL. The fields are not quoted within square brackets. I've checked I'm using the correct SQL Dialect. Is there anything else I've done wrong considering this is my first foray into Hibernate?
Hibernate version:2.1.4
Microsoft SQL Server 2000 SP3 Enterprise Edition
Mapping documents:
Code:
<hibernate-mapping>
<class
name="eg.StoCore"
table="STO_CORE">
<id
name="stockId"
type="java.lang.Integer"
column="STOCK ID">
<generator class="assigned" />
</id>
<property
name="sedol"
type="java.lang.String"
column="REF (SEDOL) No."
length="7"
/>
...........
<joined-subclass
name="eg.StoCustomer"
table="STO_CUSTOMER">
<key column="STOCK ID"/>
..........
</joined-subclass>
</class>
</hibernate-mapping>
Code:
<hibernate-configuration>
<session-factory>
<property name="dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>
<property name="connection.driver_class">
net.sourceforge.jtds.jdbc.Driver
</property>
<property name="connection.url">
jdbc:jtds:sqlserver://YY/XX
</property>
<property name="connection.username">ZZ</property>
<property name="connection.password">ZZ</property>
<property name="connection.pool_size">1</property>
<property name="show_sql">true</property>
<property name="query.substitutions">yes 'Y', no 'N'</property>
<property name="proxool.pool_alias">pool1</property>
<property name="jdbc.batch_size">0</property>
<property name="jdbc.use_streams_for_binary">true</property>
<property name="max_fetch_depth">1</property>
<property name="cache.region_prefix">hibernate.test</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.provider_class">
net.sf.ehcache.hibernate.Provider
</property>
<mapping resource="Sto.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():Code:
Query query = session.createQuery("select s from StoCustomer as s where s.sedol = :sedol");
query.setString("sedol", "0048776");
Hibernate is generating the following query which is broken..
Code:
select
stocustome0_.STOCK ID as x0_0_
from
STO_CUSTOMER stocustome0_
inner join
STO_CORE stocustome0__1_
on stocustome0_.STOCK ID=stocustome0__1_.STOCK ID
where (stocustome0__1_.REF (SEDOL) No.=? )
It should be something like:
Code:
SELECT
stocustome0_.[STOCK ID] AS x0_0_
FROM
STO_CUSTOMER stocustome0_
INNER JOIN
STO_CORE stocustome0__1_
ON stocustome0_.[STOCK ID] = stocustome0__1_.[STOCK ID]
WHERE (stocustome0__1_.[REF (SEDOL) No.] = ?)
Thanks
Andrew