-->
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.  [ 7 posts ] 
Author Message
 Post subject: HQL query error?
PostPosted: Mon Jun 02, 2008 9:30 am 
Newbie

Joined: Mon Aug 20, 2007 9:30 am
Posts: 6
I use this code to query a table:

Session session;
Transaction tx;
Query query;
List list = null;
try {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
session = sf.openSession();
tx = session.beginTransaction();

String hql="from Patient";
query=session.createQuery(hql);

list=query.list();
session.close();
sf.close();
} catch (Exception e) {
e.printStackTrace();
}
But got this error:

Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "from" at line 1, column 9.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 9:49 am 
Newbie

Joined: Sat May 31, 2008 2:06 pm
Posts: 4
on your entities what is the name of your table ?
Is it extremely as you type it ? capital P or lower p ?

EDIT : extremely ? Exactly i mean ...
if you have Patient.java then that is not it, if you have patient.java try it with lower letter


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 9:29 pm 
Newbie

Joined: Mon Aug 20, 2007 9:30 am
Posts: 6
The table is "Patient". The error is not related the table name. Nometter what table name I input, it always produce the same error:
net.sf.hibernate.exception.SQLGrammarException: Could not execute query
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:58)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.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.QueryImpl.list(QueryImpl.java:49)
at db.SearchDatabase.main(SearchDatabase.java:47)
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "from" at line 1, column 9.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:263)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:236)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:67)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:784)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
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)
... 2 more
Caused by: java.sql.SQLException: Syntax error: Encountered "from" at line 1, column 9.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 25 more
Caused by: ERROR 42X01: Syntax error: Encountered "from" at line 1, column 9.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 19 more

It
seems that the HQL search sentence is wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 2:00 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
String hql="from
Code:
Patient
";

Patient should be class name if yes and you are still getting error then try
from Patient patient. That would resolved your problem.But still i would say that there is problem to register Patient class with Hibernate.Please post your hibernate log to us

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 9:43 pm 
Newbie

Joined: Mon Aug 20, 2007 9:30 am
Posts: 6
Hi,

The class is PatientList and the table is Patient. They are defined in a configuration file Patient.hbm.xml:

<class
name="db.PatientList"
table="Patient"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

I can insert a PatientList instance into Patient table. the problem will happen when query the table.
Where can I find the hibernate log file? I found that there are some log files in the database/log directory. But I can't read it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 11:34 pm 
Newbie

Joined: Sun Jan 28, 2007 10:37 pm
Posts: 4
Location: Wollongong
I think you actually want to execute "from PatientList"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 7:07 am 
Newbie

Joined: Sat May 31, 2008 2:06 pm
Posts: 4
swd847 wrote:
I think you actually want to execute "from PatientList"


yes i think so too.
either PatientList
or db.PatientList

Logs should be in your servers ( JBoss, Tomcat ) folder, somewhere in there !


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