-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL Query - invalid query
PostPosted: Thu Jul 08, 2010 9:15 pm 
Newbie

Joined: Thu Jul 08, 2010 9:11 pm
Posts: 1
I'm developing an app using Hibernate 3.5.3 and SmartGWT 2.2 (the SmartGWT doesn't really come into it here, but just for completeness) on NetBeans 6.9.

For the purposes of this exercise, I created a very simple MySQL database, with just one table, named 'users'. That table has just two columns, 'username' and 'password'.

The problem is that when I try to run any query in the HQL Query window (a window in NetBeans where you can run HQL queries - I believe a similar window exists in Eclipse), I get the result "Invalid Query." in the SQL tab and, when I execute the query, the following error in the Results tab:

Code:
org.hibernate.hql.ast.QuerySyntaxException: Users is not mapped [from Users]
   at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
   at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
   at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
   at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)


It doesn't matter what the query is - I get the same result. The example above was generated by running "from Users".

I know I can actually connect to the database, because I can create the reverse engineering file (and the subsequent class).

Here's my hibernate.cfg.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db</property>
    <property name="hibernate.connection.username">db_user</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <mapping resource="com/firmname/server/Users.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


Here's the generated hibernate.reveng.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
  <schema-selection match-catalog="db"/>
  <table-filter match-name="users"/>
</hibernate-reverse-engineering>


Here's the generated Users.hbm.xml:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 09/07/2010 11:01:15 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="com.firmname.server.Users" table="users" catalog="db">
        <id name="username" type="string">
            <column name="username" length="45" />
            <generator class="assigned" />
        </id>
        <property name="password" type="string">
            <column name="password" length="45" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


I've looked on all the forums I could find and not found much. Most people having a similar problem are finding it in code, not using the HQL Query window. There was some talk about Hibernate having problems with case, so I tried it changing everything to all lower case (i.e., 'users'), but that changed nothing.

Thanks in advance for any help.


Top
 Profile  
 
 Post subject: Re: HQL Query - invalid query
PostPosted: Fri Sep 10, 2010 8:32 pm 
Newbie

Joined: Fri Sep 10, 2010 8:13 pm
Posts: 1
I have the same problem, my OS is win7 64 bits, netbeans 6.9.1. I have reviewed a thousand times and nothing. I'm using the sample DB that comes by default ide.

error:
org.hibernate.hql.ast.QuerySyntaxException: Customer Is Not mapped [from Customer]

hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/sample</property>
<property name="hibernate.connection.username">app</property>
<property name="hibernate.connection.password">app</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping resource="prueba2/DiscountCode.hbm.xml"/>
<mapping resource="prueba2/Customer.hbm.xml"/>
<mapping resource="prueba2/ProductCode.hbm.xml"/>
<mapping resource="prueba2/PurchaseOrder.hbm.xml"/>
<mapping resource="prueba2/Product.hbm.xml"/>
<mapping resource="prueba2/MicroMarket.hbm.xml"/>
<mapping resource="prueba2/Manufacturer.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Customer.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">
<!-- Generated Sep 10, 2010 11:06:49 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="prueba2.Customer" schema="APP" table="CUSTOMER">
<id name="customerId" type="int">
<column name="CUSTOMER_ID"/>
<generator class="assigned"/>
</id>
<property name="discountCode" type="char">
<column length="1" name="DISCOUNT_CODE" not-null="true"/>
</property>
<property name="zip" type="string">
<column length="10" name="ZIP" not-null="true"/>
</property>
<property name="name" type="string">
<column length="30" name="NAME"/>
</property>
<property name="addressline1" type="string">
<column length="30" name="ADDRESSLINE1"/>
</property>
<property name="addressline2" type="string">
<column length="30" name="ADDRESSLINE2"/>
</property>
<property name="city" type="string">
<column length="25" name="CITY"/>
</property>
<property name="state" type="string">
<column length="2" name="STATE"/>
</property>
<property name="phone" type="string">
<column length="12" name="PHONE"/>
</property>
<property name="fax" type="string">
<column length="12" name="FAX"/>
</property>
<property name="email" type="string">
<column length="40" name="EMAIL"/>
</property>
<property name="creditLimit" type="java.lang.Integer">
<column name="CREDIT_LIMIT"/>
</property>
</class>
</hibernate-mapping>

please help us..


Top
 Profile  
 
 Post subject: Re: HQL Query - invalid query
PostPosted: Fri Sep 10, 2010 11:01 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
These are more likely due to your IDE setup problems, not hibernate itself. I would check to ensure your hibernate.cfg.xml is in your root classpath, and your mapping file is in the right classpath sub folder.

Also try write a standalone main Java client that loads the hibernate session and run your query. See manual on how to setup one. Get this working and apply it in your IDE settings.

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


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