-->
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.  [ 4 posts ] 
Author Message
 Post subject: Unexpected token: FROM in statement [select from]
PostPosted: Thu Jun 17, 2004 1:18 pm 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
I'm getting this unique problem from a simple query. I'm using Hibernate 2.1 and its talking to HSQL.

When I run the following statement:

Code:
            session.find("from HexMail");


I get the following results:

Code:
net.sf.hibernate.JDBCException: Could not execute query
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1546)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
   at zarnett.hibernate.example.HexEmailRunner.main(HexEmailRunner.java:87)
Caused by: java.sql.SQLException: Unexpected token: FROM in statement [select  from]


Prior to this I was doing simple calls such as:

Code:
            final HexEmail retrieveEmail =
                (HexEmail)session.load(HexEmail.class,generatedID);


which all worked fine.

My mapping file is pretty simple and looks as follows:

Code:
<hibernate-mapping>

    <class name="zarnett.hibernate.example.HexEmail" table="HexMail">

        <id name="emailID" column="EmailID" type="integer" unsaved-value="0">
            <generator class="increment"/>
        </id>

        <property name="message">
            <column name="Message" length="1000" not-null="true"/>
        </property>

    </class>

</hibernate-mapping>


As well, when I create my session I am doing the following:

Code:
           // Allow hibernate to load a mapping file using getResourceAsStream()
           Configuration config = new Configuration();
           config.addClass(zarnett.hibernate.example.HexEmail.class);
          
           sessionFactory = config.buildSessionFactory();


By the time I have made this call I have done several transactions including a save, several retrievals (including retrievals on rows that do not exist). I have not closed the session yet either.

Any ideas on what's wrong?

As well, when I do something like

Code:
"from HexEmail as hm where hm.EmailId=?"


It says it was not expecting the "as" clause.

Thanks in advance for any help!


Top
 Profile  
 
 Post subject: Same Problem - Used fully qualified object name.
PostPosted: Fri Jun 18, 2004 9:29 am 
Newbie

Joined: Fri Mar 19, 2004 7:06 pm
Posts: 6
I just upgraded to hibernate 2.1.4 using MySQL v3 (no idea if it has anything to do with it) and am noticing this same problem with just 1 mapping. If I fully qualify the object name within the query, it works fine, but fails when it's not fully qualified.

ex:

Code:
<hibernate-mapping package="com.mypackage" auto-import="false">

...

<class name="TemplateImage" table="csf_template_image" >

  <id name="templateImageID" type="int" unsaved-value="0" >
    <column name="template_image_id" sql-type="int" not-null="true"/>
    <generator class="native"/>
  </id>

  <property name="image" column="image" type="blob" />
      
  <many-to-one name="language" class="com.mypackage.Language" column="language_id"/>

</class>

...

</hibernate-mapping>



My corresponding "TemplateImage" class is a simple POJO, nothing fancy.

The unqualified object query that fails:

Code:
List list = session.find("from TemplateImage");


The fully qualified object query that works fine:

Code:
List list = session.find("from com.mypackage.TemplateImage");


I have about 30 other objects that I have mapped, and I have been using the unqualified object query for all of them... until now. The only object that I have to fully qualify the object name is this TemplateImage object. I verified that there are no duplicate mappings of this object, and I've reviewed the mapping for any mistakes and haven't found any.

The only difference between TemplateImage and the rest of my objects is that TemplateImage contains a blob.

The exception text:

2004-06-18 08:21:18,453 [Thread-5] ERROR net.sf.hibernate.util.JDBCExceptionReporter - Could not execute query
java.sql.SQLException: Syntax error or access violation, message from server: "You have an error in your SQL syntax near 'from' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 18, 2004 9:45 am 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
Last night I added the following to my mapping:

Code:
<hibernate-mapping package="zarnett.hibernate.example" auto-import="true">


When I full qualify the entry such as:

Code:
session.find("from zarnett.hibernate.example.HexMail");


I get

Code:
net.sf.hibernate.QueryException: undefined alias: zarnett [from zarnett.hibernate.example.HexMail]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 18, 2004 9:53 am 
Newbie

Joined: Thu Jun 17, 2004 1:09 pm
Posts: 9
I figured it out (thanks to the previous poster). Aside from a typo, the key was

Code:
<hibernate-mapping package="zarnett.hibernate.example" auto-import="true">


I needed to set the package and the auto-import to true.

I can now do what I expected.

Looking at Tim's example, the auto-import needs to be set to true as well.


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