I am working with the Microsoft Northwind database and trying to create a hibernate mapping (it is a good sample of a well-known reasonably complex database)
There is a table called "Order Detail" which is giving me a lot of problems because
1) the name has a space
2) The first word, 'Order' is a SQL keyword
in accessing this table hibernate generates the following prepared statement:
select orderdetai0_.OrderID as OrderID__, orderdetai0_.ProductID as ProductID__, orderdetai0_.OrderID as OrderID0_, orderdetai0_.ProductID as ProductID0_, orderdetai0_.OrderID as OrderID0_, orderdetai0_.ProductID as ProductID0_, orderdetai0_.UnitPrice as UnitPrice0_, orderdetai0_.Quantity as Quantity0_, orderdetai0_.Discount as Discount0_ from Order Details orderdetai0_ where orderdetai0_.OrderID=?
note 'from Order Details'
and this blows up with a SQL error
Caused by: java.sql.SQLException: Incorrect syntax near the keyword 'Order'.
at net.sourceforge.jtds.jdbc.SqlMessage.toSQLException(SqlMessage.java:85)
at net.sourceforge.jtds.jdbc.SQLWarningChain.addOrReturn(SQLWarningChain.java:99)
at net.sourceforge.jtds.jdbc.Tds.submitProcedure(Tds.java:616)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.submitProcedure(PreparedStatement_base.java:195)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.execute(PreparedStatement_base.java:174)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeQuery(PreparedStatement_base.java:210)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
My question is is there a way to handle this case properly?????
_________________ Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)
|