-->
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: SQL exception (invalid use of keyword USER)
PostPosted: Thu Oct 21, 2004 6:00 am 
Newbie

Joined: Thu Oct 21, 2004 5:43 am
Posts: 2
Hi All,

I have a somewhat annoying problem. In my database (MSSQL) I have a "users" table. The convention for hibernate seems to be to name the class as the singular so I have "data.User" as a classname. When I issue a query:

String query =
"select user from user "
+ "in class data.User "
+ "where id=:id";
and call:
List list = sess.find(query, new Long(2), Hibernate.LONG);

I get an SQL exception (invalid use of keyword USER).

It works if I change the classname + xml files to use "data.XUser" but should I really have to? Is there some way to tell hibernate about keywords or should I just use a different convention for class naming?

TIA



Hibernate version: Hibernate 2.1.6

Mapping documents: n/a

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.6
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=bookmork, hibernate.connection.password=bookmork, hibernate.cglib.use_reflection_optimizer=true, hibernate.connection.pool_size=4, hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.show_sql=true, hibernate.connection.url=jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor, hibernate.connection.driver_class=com.microsoft.jdbc.sqlserver.SQLServerDriver}
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: data/User.hbm.xml
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: data.User -> USERS
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 21, 2004 5:51:58 AM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.SQLServerDialect
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
Oct 21, 2004 5:51:58 AM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Oct 21, 2004 5:51:58 AM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 4
Oct 21, 2004 5:51:58 AM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor
Oct 21, 2004 5:51:58 AM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=bookmork, password=bookmork}
Oct 21, 2004 5:51:58 AM net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: echoing all SQL to stdout
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
Oct 21, 2004 5:51:58 AM net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
Oct 21, 2004 5:51:59 AM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Oct 21, 2004 5:51:59 AM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Hibernate: select user as x0_0_ from USERS user where (id=? )
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 156, SQLState: HY000
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Incorrect syntax near the keyword 'user'.
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 16945, SQLState: HY000
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The cursor was not declared.
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 156, SQLState: HY000
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Incorrect syntax near the keyword 'user'.
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 16945, SQLState: HY000
Oct 21, 2004 5:51:59 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The cursor was not declared.
Oct 21, 2004 5:51:59 AM net.sf.hibernate.JDBCException <init>
SEVERE: Could not execute query
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Incorrect syntax near the keyword 'user'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1517)
at util.TestHibernate.main(TestHibernate.java:46)
net.sf.hibernate.JDBCException: Could not execute query
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1547)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1517)
at util.TestHibernate.main(TestHibernate.java:46)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Incorrect syntax near the keyword 'user'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSCursorRequest.openCursor(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
... 3 more
Oct 21, 2004 5:51:59 AM net.sf.hibernate.impl.SessionImpl finalize
WARNING: unclosed connection



Name and version of the database you are using: MSSQL 2000

The generated SQL (show_sql=true): Hibernate: select user as x0_0_ from USERS user where (id=? )

Debug level Hibernate log excerpt: WARN


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 11:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
How about just changing your query from
Code:
select user from user in class data.User where id=:id


to
Code:
select u from data.User as u where u.id=:id


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 6:09 pm 
Newbie

Joined: Thu Oct 21, 2004 5:43 am
Posts: 2
Thanks! That worked! I guess I should be buying the book when it comes out. :)


steve wrote:
How about just changing your query from
Code:
select user from user in class data.User where id=:id


to
Code:
select u from data.User as u where u.id=:id


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.