- This topic has 5 replies, 4 voices, and was last updated 17 years, 8 months ago by dkim18.
-
AuthorPosts
-
Gabriel Khoa BuiMemberorg.hibernate.exception.SQLGrammarException: could not load an entity: [com.deth.hibernate.EchoMessage#1] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) ............................................................................. Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.echo_message echomessag0_ where echomessag0_.id=1' at line 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941) .............................................................................
Im following the Hibernate tutorial of MyEclipse help. And I get an error that I spent lots of time to fix it. Im using MySQL 5.0, Windoze XP2, MyEclipse 5.1 GA and Tomcat 6.0. Here are the files which I coded:
1. EchoMessage.hbm.xml:<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="com.deth.hibernate.EchoMessage" table="echo_message" catalog="lathong"> <id name="id" type="java.lang.Integer"> <column name="id" precision="22" scale="0"/> <generator class="assigned"/> </id> <property name="message" type="java.lang.String"> <column name="Message" not-null="true" /> </property> </class> </hibernate-mapping>
2. EchoMessageAction.java
package com.deth.struts.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.hibernate.HibernateException; import com.deth.hibernate.EchoMessage; import com.deth.hibernate.EchoMessageDAO; import deth.utilities.AbstractBean; public class EchoMessageAction extends Action{ private static final String ECHO = "echo"; private java.util.List list; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{ EchoMessageDAO dao = new EchoMessageDAO(); try{ EchoMessage instance = dao.findById(new Integer(1)); String message = instance.getMessage(); System.out.println("message = " + message); request.setAttribute(ECHO, list.add(message)); } catch (HibernateException he) { he.printStackTrace(); } finally{ try{ dao.getSession().close(); } catch (Exception e) { e.printStackTrace(); } } return mapping.findForward(AbstractBean.SUCCESS); } }
If you mind showing me the answer. Thank you so much.
Riyad KallaMemberCan you add a property “show_sql” to your hibernate.cfg.xml file and set it’s value to “true” and re-run your app, then right before the error, look for the actual SQL that Hibernate is trying to execute?
Also can you generate the DDL from your table using the DB tool and post it here for me to look at?
Gabriel Khoa BuiMemberThanx, I got my error. It was so strange, the table named users which I created from MySQL database, then in HQL in made a select statement like this: FROM users. It returned error. But I changed the syntax to SELECT Users, it was okie. What fun.
Anyway, thank for your enthusiasm. This is an useful forum in which I received the anwsers quickly. That is so different from ohers.
Best regars, Khoa.
Riyad KallaMemberKhoa, nice catch, actually HQL requires you use Object names, not the table names, which is why you had to use “Users” with a capital.
I’ve tripped up on that one more than a enough times myself.
bilisMembertry removing –catalog=”lathong”– from your autogenerated mapping hbm file, at least that work for me 🙂
dkim18MemberHi,
I am trying to excute very simple hql.
+++++++++++++++++++++++++++++public class ResidencyDAOImpl extends HibernateDaoSupport implements ResidencyDAO{
…
…
public void printResidencyTable(){
Session session = getSession();String hqlStr =”FROM Person”;
Query query = getSession().createQuery(hqlStr);
System.out.println(“query: ” + query);List list = query.list();
…
…but I have this error.
Hibernate: select person0_.id as id, person0_.version_num as version2_6_, person0_.family_name as family3_6_, person0_.given_name as given4_6_, person0_.relocate as relocate6_ from jhu786..person person0_
Exception in thread “main” org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1565)
at org.hibernate.loader.Loader.list(Loader.java:1545)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:840)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at edu.jhu.jhu786.hib.ResidencyDAOImpl.printResidencyTable(ResidencyDAOImpl.java:60)
at edu.jhu.jhu786.hib.TestDriver.main(TestDriver.java:72)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.person person0_’ at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)+++++++++++++++++++++++
This used to work befor.
any idea?
thx,
p.s.
there were two dots btween “jhu786..person” and this is causing this problem, but i don’t know why it is putting two dots.
-
AuthorPosts