-->
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.  [ 5 posts ] 
Author Message
 Post subject: Undefine Alias error
PostPosted: Tue Apr 20, 2004 11:02 am 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
Hi,

I'm trying to execute the following SQL statement:
Code:
SELECT d, p.price
FROM StateDestinationData sd, DestinationData d, OfferData o,
  PackageData p
WHERE sd.stateId = "+stateId+" AND sd.destId = d.destId AND
d.destId = o.destId AND o.offerId = p.offerId "
p.price = (SELECT min(price)
                FROM PackageData WHERE offerId = o.offerId)
ORDER BY d.destName ASC


but am getting the following error:

Code:
com.cendant.trg.getaways.common.TRGDatabaseException: Error in findDestsWithPkgPrice():net.sf.hibernate.QueryException: undefined alias: price [SELECT d, p.price FROM com.cendant.trg.getaways.model.StateDestinationData AS sd, com.cendant.trg.getaways.model.DestinationData AS d, com.cendant.trg.getaways.model.OfferData AS o, com.cendant.trg.getaways.model.PackageData AS p WHERE sd.stateId = 8 AND sd.destId = d.destId AND d.destId = o.destId AND o.offerId = p.offerId p.price = (SELECT min(price) FROM com.cendant.trg.getaways.model.PackageData WHERE offerId = o.offerId) ORDER BY d.destName ASC]
   at com.cendant.trg.getaways.db.DestinationDAO.findDestsWithPkgPrice(DestinationDAO.java:105)
   at com.cendant.trg.getaways.db.test.DestinationDAOTest.testDestinationSelect(DestinationDAOTest.java:57)
   at java.lang.reflect.Method.invoke(Native Method)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)


Help please!!!


Top
 Profile  
 
 Post subject: Undefined Alias Error
PostPosted: Tue Apr 20, 2004 11:36 am 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
Okay, I found 1 problem, I forgot the AND before the price constraint. So my query looks like:

Code:
SELECT d.*, p.price FROM com.cendant.trg.getaways.model.StateDestinationData AS sd, com.cendant.trg.getaways.model.DestinationData AS d, com.cendant.trg.getaways.model.OfferData AS o, com.cendant.trg.getaways.model.PackageData AS p
WHERE sd.stateId = 8 AND
sd.destId = d.destId AND
d.destId = o.destId AND
o.offerId = p.offerId
AND p.price = (SELECT min(price)
                       FROM com.cendant.trg.getaways.model.PackageData
                       WHERE offerId = o.offerId)
ORDER BY d.destName ASC


but I'm still getting the same error. All the tables in the query are mapped.

Please help!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 12:08 pm 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
Here's the mapping doc form the PackageData class:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.cendant.trg.getaways.model">
   <class name="PackageData" table="Package" dynamic-update="true" dynamic-insert="true">
      <id name="pkgId" column="pkg_id">
         <generator class="sequence">
            <param name="sequence">pkg_id_sq</param>
         </generator>
      </id>
      <property name="offerId" column="offer_id"/>
      <property name="pkgName" column="pkg_name"/>
      <property name="description" column="description"/>
      <property name="price" column="price"/>
      <property name="priceDesc" column="price_desc"/>
      <property name="numNights" column="num_nights"/>
      <property name="numDays" column="num_days"/>
      <property name="itemSku" column="item_sku"/>
      <property name="web4Digit" column="web_4_digit"/>
      <property name="image1" column="image1"/>
      <property name="image2" column="image2"/>
      <property name="stateId" column="state_id"/>
      <property name="userId" column="user_id"/>
      <property name="dateModified" column="date_modified"/>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 2:17 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it seems you're mixing pure sql & hql queries, not really object oriented query so just call it with jdbc, subselects like yours are not supported, furthermore if you are query unmapped table


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 20, 2004 2:22 pm 
Newbie

Joined: Thu Apr 01, 2004 12:37 pm
Posts: 9
Thanks. HQL doesn't really make sense to me so I'm using regular SQL.

The error was being generated because the subselect didn't contain an alias. Changing the subselect to
Code:
SELECT min(pkg2.price) FROM PackageData pkg2 WHERE pkg2.offerId = offer.offerId
was the solution.


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