-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Table Names with spaces??
PostPosted: Wed Mar 03, 2004 2:48 pm 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
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)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Escape the table name in the mapping. like this <class ... table="`some table`"> or whatever the escape character for the db you use is (I hope it is not access)


Top
 Profile  
 
 Post subject: Tables with spaces
PostPosted: Wed Mar 03, 2004 6:19 pm 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
Thanks = d'oh I should have tried that
I tried table="`Order Details`"
and table="\`Order Details\`"
but for SQLServer the answer is
table="[Order Details]"

_________________
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.