-->
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.  [ 2 posts ] 
Author Message
 Post subject: Executin a normal query
PostPosted: Sun Aug 10, 2008 3:44 am 
Newbie

Joined: Sun Aug 10, 2008 3:25 am
Posts: 2
Location: South Africa
Im trying to run this code but it gives me the bellow exception:
any help will be appriciated.
Regards

EntityManager em = Contexts.getEntityManager();

// create a query with named parameters

Query query = em.createQuery("from User user "
+ " where user.username = :username "
+ " and user.password = :password");

// bind parameters
query.setParameter("username", getUsername());
query.setParameter("password", getPassword());



exception

javax.servlet.ServletException: Incorrect syntax near the keyword 'user'.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
fi.tavutaito.filter.EntityManagerFilter.doFilter(EntityManagerFilter.java:78)

root cause

java.sql.SQLException: Incorrect syntax near the keyword 'user'.
net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
org.hibernate.loader.Loader.doQuery(Loader.java:662)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2145)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:333)
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:756)
org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:63)
fi.tavutaito.action.LoginAction.login(LoginAction.java:41)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.el.parser.AstValue.invoke(AstValue.java:172)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:71)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:96)
javax.faces.component.UICommand.broadcast(UICommand.java:384)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:473)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:785)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:243)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
fi.tavutaito.filter.EntityManagerFilter.doFilter(EntityManagerFilter.java:78)


Top
 Profile  
 
 Post subject: Re: Executin a normal query
PostPosted: Sun Aug 10, 2008 4:32 am 
Newbie

Joined: Sun Aug 10, 2008 3:25 am
Posts: 2
Location: South Africa
i have solved the problem,
the solutuon under this topic:
http://forum.hibernate.org/viewtopic.php?t=989077&highlight=incorrect+syntax+keyword


abdelghani.tag wrote:
Im trying to run this code but it gives me the bellow exception:
any help will be appriciated.
Regards

EntityManager em = Contexts.getEntityManager();

// create a query with named parameters

Query query = em.createQuery("from User user "
+ " where user.username = :username "
+ " and user.password = :password");

// bind parameters
query.setParameter("username", getUsername());
query.setParameter("password", getPassword());



exception

javax.servlet.ServletException: Incorrect syntax near the keyword 'user'.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
fi.tavutaito.filter.EntityManagerFilter.doFilter(EntityManagerFilter.java:78)

root cause

java.sql.SQLException: Incorrect syntax near the keyword 'user'.
net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
org.hibernate.loader.Loader.doQuery(Loader.java:662)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2145)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:333)
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:756)
org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:63)
fi.tavutaito.action.LoginAction.login(LoginAction.java:41)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.el.parser.AstValue.invoke(AstValue.java:172)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:71)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:96)
javax.faces.component.UICommand.broadcast(UICommand.java:384)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:473)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:785)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:243)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
fi.tavutaito.filter.EntityManagerFilter.doFilter(EntityManagerFilter.java:78)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.