-->
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: net.sf.hibernate.QueryException: in expected:
PostPosted: Tue Nov 23, 2004 12:52 pm 
Newbie

Joined: Tue Nov 23, 2004 12:25 pm
Posts: 9
Hi there,

I,m trying to list a table content with:

public java.util.List getList(String hql) throws Exception{
Session session = factory.openSession();
List pessoas = session.find(hql);
for(int indice=0; indice<pessoas.size(); indice++)
{
Amigo amigo = (Amigo)pessoas.get(indice);

}
session.flush();
session.close();
return pessoas;
}

and calling by :

dao.getList("from amigos Amigo");
System.out.println(amigo.getTelefone());

inside a main method.

Just tryed to use "SELECT telefone FROM Amigo" in the parameter of getList() but receive the same message:

net.sf.hibernate.QueryException: in expected: Amigo [from amigos Amigo]
at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:142)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
at HIBERNA.AmigoDAO.getList(AmigoDAO.java:31)
at HIBERNA.TesteAmigo.main(TesteAmigo.java:19)

I had read about to use HQL sintax and i did.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 03, 2004 5:49 pm 
Beginner
Beginner

Joined: Wed Mar 17, 2004 4:13 pm
Posts: 21
Location: San Diego, CA
Try changing your query to:

Code:
from Amigo as amigos


You need to list the object before the variable...just like in SQL (except you list the table before the variable name)

Since you don't do anything with amigos, you could probably leave it out and just say:

Code:
from Amigo


Buena suerte!

Chrisjan


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.