-->
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: getting unexpected token: error
PostPosted: Sat Mar 10, 2012 1:48 pm 
Newbie

Joined: Sat Mar 10, 2012 1:32 pm
Posts: 1
Hi all,

I have One to many relationship in the database and its represent "One Customer can Many Orders" in the system.
Then when the customer name selected from the combo provided, it must get the relevant customerId and using that customerId i need to filter the order details like orderNumber..ect.

But when im trying to put the Inner join like this its triggers the error (unexpected token error)

this wht i did
Code:
String hql = "select distinct order from" + " Order order "
            + "join order.Customer customer "
            + "where customer.customerID=:customerId";

      Query orderQuary = session.createQuery(hql);
      query.setParameter("customerId", customerId);

      List<Order> orderList = orderQuary.list();


error im getting:
Code:
Hibernate: select customer0_.customerId as customerId0_, customer0_.customerName as customer2_0_, customer0_.customerAddress as customer3_0_, customer0_.customerDelivaryAddress as customer4_0_, customer0_.customerTPNumber as customer5_0_, customer0_.persontoAtten as personto6_0_, customer0_.customeremail as customer7_0_, customer0_.persontoAttanTPNumber as personto8_0_ from customer customer0_
Exception in thread "AWT-EventQueue-0" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: order near line 1, column 17 [select distinct order from com.pearledge.domain.Order order join order.Customer customer where customer.customerID=:customerId]
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
   at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
   at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
   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)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
   at $Proxy0.createQuery(Unknown Source)
   at com.pearledge.UI.CreateOrderPanel.getCustomerPreviousOrderNumber(CreateOrderPanel.java:407)
   at com.pearledge.UI.CreateOrderPanel.actionPerformed(CreateOrderPanel.java:258)
   at javax.swing.JComboBox.fireActionEvent(Unknown Source)
   at javax.swing.JComboBox.setSelectedItem(Unknown Source)
   at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
   at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
   at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   at java.awt.EventQueue.access$000(Unknown Source)
   at java.awt.EventQueue$1.run(Unknown Source)
   at java.awt.EventQueue$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue$2.run(Unknown Source)
   at java.awt.EventQueue$2.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


this is my hbm files:order.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">
<hibernate-mapping package="com.pearledge.domain">

<class name="Order" table="orders">
        <id name="ourOrderId" column="ourOrderID">
            <generator class="native" />
        </id>

        <property name="ourOrderName" column="ourOrderName" />
        <property name="orderDate" type="date"  column="orderdate" />
        <property name="delivaryDate" type="date" column="delivaryDate" />
        <property name="customerPONumber" column="customerPONumber" />

        <many-to-one name="customer" class="com.pearledge.domain.Customer" fetch="select">
            <column name="customerId" not-null="true" />
        </many-to-one>

    </class>
</hibernate-mapping>


customer.hbm.xml file:
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">
<hibernate-mapping package="com.pearledge.domain">
   <class name="Customer" table="customer">
      <id name="customerID" column="customerId">
         <generator class="increment"></generator>
      </id>
      <property name="customerName" column="customerName"></property>
      <property name="customerAddress" column="customerAddress"></property>
      <property name="customerDelivaryAddress" column="customerDelivaryAddress"></property>
      <property name="customerTPNumber" column="customerTPNumber"></property>
      <property name="personToAtten" column="persontoAtten"></property>
      <property name="customerEmailAddress" column="customeremail"></property>
      <property name="personToAttenTPNumber" column="persontoAttanTPNumber"></property>
      
      <set name="orderList" table="orders" inverse="true" lazy="true"
         fetch="select">
         <key>
            <column name="customerID" not-null="true" />
         </key>
         <one-to-many class="com.pearledge.domain.Order" />
      </set>
   </class>
</hibernate-mapping>


Why this happen? any thoughts to recover this? please help me since im stuck in this place several hours :-(((


Top
 Profile  
 
 Post subject: Re: getting unexpected token: error
PostPosted: Mon Mar 12, 2012 3:24 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Try by removing the first part 'select distinct order '

Code:
String hql = "from" + " Order order "
            + "join order.Customer customer "
            + "where customer.customerID=:customerId";
...


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.