wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Query error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query error" Watch "Query error" New topic

Query error

Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
public boolean findUserName(String uname){
SessionFactory instance = Singleton.getPersistenceManager();

boolean result = false;

try {
Session session = instance.openSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery("from UserDirectory d where d.username = :uname");
q.setParameter("uname", uname);
result = q.list().isEmpty();

} catch (HibernateException e) {
return result;

And I receive the following error

net.sf.hibernate.QueryException: in expected: d [from UserDirectory d where d.username = :uname]

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.token(PreprocessingParser.java:123)

at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)

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.QueryImpl.list(QueryImpl.java:39)

at com.users.core.UserDirectory.findUserName(UserDirectory.java:136)

at com.users.core.UserDirectory.main(UserDirectory.java:176)

Any idea?
King Regards!
Prakash Jebaraj

Joined: Mar 14, 2005
Posts: 5

Check whether you have added UserDirectory in the configuration.

Prakash Jebaraj
Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
I add the class UserDirectory on my
userDirectorydb.cfg.xml that is like the hibernate.cfg.xml
and contains something like

<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/userDirectoryNews</property>
<property name="connection.username">news</property>
<property name="connection.password">news</property>

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="use_outer_join">true</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
<property name="show_sql">true</property>

<!-- Mapping files -->
<mapping resource="com/users/core/UserDirectory.hbm.xml" />

is on the same folder as UserDirectory.java

King regards

I agree. Here's the link: http://aspose.com/file-tools
subject: Query error
Similar Threads
Hibernate - Query Exception
Hibernate Query Exception
hibernate exception 'unexpected token as'
Illegal Start of the "try" Block?!
couldn't resolve property exception in Hibernate