-->
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: HQL Exception when not using HQL?
PostPosted: Mon Jul 23, 2007 7:05 pm 
Newbie

Joined: Mon Jul 23, 2007 6:52 pm
Posts: 1
Hibernate Version: 3.2

I'm having a strange problem with Hibernate and Derby. I'm getting HQL Syntax Exceptions even though I'm not using HQL.

It throws the exception:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: *

when I do
Form form = new Form();
form = (Form)session.createQuery("select * from USERTABLE where EMAIL = " + email).uniqueResult();

hibernate.cfg.xml

Code:
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
        <property name="connection.url">jdbc:derby://localhost:1527/info</property>
        <property name="connection.username">app</property>
        <property name="connection.password">app</property>
       
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
       
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
       
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>
       
        <!-- Mapping files -->

        <mapping resource="Form.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Form.hbm.xml
Code:
<hibernate-mapping>
    <class name="myPackage.Form" table="USERTABLE">
        <id name="userID" type="int">
            <generator class="increment"/>
        </id>
       
        <property name="userName" type="string"/>
        <property name="password" type="string"/>
        <property name="email" type="string"/>   
        <property name="userState" type="string"/>   
        <property name="city" type="string"/>   
    </class>
</hibernate-mapping>



Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 5:13 am 
Newbie

Joined: Thu Jul 19, 2007 5:59 am
Posts: 3
Location: Romania
Maybe you mean:

Code:
Query query = session.createQuery("select form from Form as form where form.email = ?");
query.setString(1, email);
Form form = (Form) query.uniqueResult();


Doing session.createQuery(queryString) implies you use HQL. Please read the documentation, as ORM is a complicated thing and you cannot just fix problems by trial&error or by keeping asking others.
For HQL read: http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html


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.