File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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(

at net.sf.hibernate.hql.ClauseParser.token(

at net.sf.hibernate.hql.PreprocessingParser.token(

at net.sf.hibernate.hql.ParserHelper.parse(

at net.sf.hibernate.hql.QueryTranslator.compile(

at net.sf.hibernate.hql.QueryTranslator.compile(

at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(

at net.sf.hibernate.impl.SessionImpl.getQueries(

at net.sf.hibernate.impl.SessionImpl.find(

at net.sf.hibernate.impl.QueryImpl.list(

at com.users.core.UserDirectory.findUserName(

at com.users.core.UserDirectory.main(

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"></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

King regards

I agree. Here's the link:
subject: Query error