-->
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: createQuery fails with table name containing a space
PostPosted: Wed Aug 02, 2006 2:29 pm 
Newbie

Joined: Wed Aug 02, 2006 2:06 pm
Posts: 3
Location: Moorestown, NJ
Hibernate version: 3.0.2

How do you call createQuery when a legacy table name contains a space. A SQL Server database table name is "dbo.Poll C". I am using the alias m. createQuery will not work when the table name has a space before the "C".

I tried the following but none work:

Query q = session.createQuery("from dbo.Message t inner join dbo.Poll C m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join 'dbo.Poll C' m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join dbo.'Poll C' m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join dbo.[Poll C] m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join dbo.\"Poll C\" m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join dbo.%Poll C% m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join dbo.Poll_C m on t.ID = m.MessageId");

Query q = session.createQuery("from dbo.Message t inner join dbo.Poll C m on t.ID = m.MessageId");

How do I escape the space in the table name?

Name and version of the database you are using: SQL Server 2005 Express Edition

Thank you.

_________________
Glenn Gifford


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 2:51 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
use HQL and use the class name in the query

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject: Re: createQuery fails with table name containing a space
PostPosted: Thu Mar 03, 2011 3:26 pm 
Newbie

Joined: Thu Mar 03, 2011 3:24 pm
Posts: 9
I had no idea what the above answer actually meant during my first few days using hibernate. So, to add, in order to escape the table name, use

@Table(name = "`comment`")

on the offending class, but then use the class's name ("Comment" in this case) in your queries-


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.