-->
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: Hibernate working with MySQL SQL Error 1064
PostPosted: Thu Mar 03, 2005 4:50 pm 
Newbie

Joined: Thu Mar 03, 2005 4:35 pm
Posts: 5
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping >

<class name="com.bankofny.girt.pa.ejb.role.Role" table="roles" >
<id name="idPk" column="ID_PK" type="int">
<generator class="native" />
</id>
<property name="name" column="name" type="java.lang.String" not-null="true" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
public class RoleHibernate extends BaseHibernate {


public List getRoles() {
List roles = new ArrayList() ;
try {
Session session = super.getSession();
// System.out.println("$$$$$$$$$$ right before attempting to get all the roles from the table $$$$$$$$$");
roles = session.find("from Roles");
session.flush();
session.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return roles;
}
}


public class BaseHibernate {

private SessionFactory sf;

public Session getSession() throws Exception {
Configuration cfg = new Configuration()
.addClass(com.bankofny.girt.pa.ejb.person.Person.class)
.addClass(com.bankofny.girt.pa.ejb.role.Role.class);
SessionFactory sf = cfg.buildSessionFactory();
return sf.openSession();
}
}

Full stack trace of any exception that occurs:

15:12:31,750 WARN [EhCacheProvider] Could not find configuration [net.sf.hibern
ate.cache.StandardQueryCache]; using defaults.
15:12:31,980 INFO [STDOUT] Hibernate: select from
15:12:32,030 WARN [JDBCExceptionReporter] SQL Error: 1064, SQLState: 42000
15:12:32,030 ERROR [JDBCExceptionReporter] You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right sy
ntax to use near 'from' at line 1
15:12:32,040 WARN [JDBCExceptionReporter] SQL Error: 1064, SQLState: 42000
15:12:32,040 ERROR [JDBCExceptionReporter] You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right sy
ntax to use near 'from' at line 1
15:12:32,050 INFO [STDOUT] net.sf.hibernate.exception.SQLGrammarException: Coul
d not execute query
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConver
ter.java:69)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionH
elper.java:29)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1523)
at com.bankofny.girt.pa.ejb.role.RoleHibernate.getRoles(RoleHibernate.ja
va:30)
at com.bankofny.girt.pa.handlers.RoleHandler.getroleList(RoleHandler.jav
a:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.faces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.j
ava:79)
at com.sun.faces.el.impl.ArraySuffix.evaluate(ArraySuffix.java:167)
at com.sun.faces.el.impl.ComplexValue.evaluate(ComplexValue.java:151)
at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEval
uatorImpl.java:243)
at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:173)

at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)

at javax.faces.component.UIData.getValue(UIData.java:527)
at javax.faces.component.UIData.getDataModel(UIData.java:856)
at javax.faces.component.UIData.setRowIndex(UIData.java:379)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRen
derer.java:65)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.jav
a:683)
at javax.faces.component.UIData.encodeBegin(UIData.java:681)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(
HtmlBasicRenderer.java:433)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(
HtmlBasicRenderer.java:440)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(Group
Renderer.java:130)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.
java:701)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(
HtmlBasicRenderer.java:435)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRe
nderer.java:233)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.
java:701)
at javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:
607)
at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:544)
at com.sun.faces.taglib.html_basic.PanelGridTag.doEndTag(PanelGridTag.ja
va:460)
at org.apache.jsp.templates.topLayout_jsp._jspx_meth_h_panelGrid_0(topLa
yout_jsp.java:206)
at org.apache.jsp.templates.topLayout_jsp._jspx_meth_f_view_0(topLayout_
jsp.java:147)
at org.apache.jsp.templates.topLayout_jsp._jspService(topLayout_jsp.java
:96)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
92)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
atcher.java:703)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationD
ispatcher.java:589)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDis
patcher.java:499)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary
.java:966)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.jav
a:581)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:13
7)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:177)
at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:756
)
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(Inser
tTag.java:881)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:473)

at org.apache.jsp.pages.role.RoleList_jsp._jspx_meth_tiles_insert_0(Role
List_jsp.java:105)
at org.apache.jsp.pages.role.RoleList_jsp._jspService(RoleList_jsp.java:
60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
92)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
atcher.java:703)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(Applica
tionDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD
ispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis
patcher.java:312)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImp
l.java:322)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.
java:130)
at oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(
ViewHandlerImpl.java:134)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePha
se.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecur
ityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBa
15:12:32,111 INFO [STDOUT] se.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:683)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.sql.SQLException: You have an error in your SQL syntax; check th
e manual that corresponds to your MySQL server version for the right syntax to u
se near 'from' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2376)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.ja
va:1860)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:
1705)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:89)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:880)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:273)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:138)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)
at net.sf.hibernate.loader.Loader.list(Loader.java:1054)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)
... 100 more
Name and version of the database you are using:
MySQL version 4.1 and mysql-connector-java-3.1.7-bin

The generated SQL (show_sql=true):
15:12:31,980 INFO [STDOUT] Hibernate: select from

Debug level Hibernate log excerpt:
?????


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 4:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
from Role, not from roles -> HQL operates on classes, not tables


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 5:20 pm 
Newbie

Joined: Thu Mar 03, 2005 4:35 pm
Posts: 5
Thanks, that has it working now.


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.