-->
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: index function in hql causes SQLGrammarException
PostPosted: Tue Mar 29, 2005 6:04 am 
Newbie

Joined: Mon Mar 14, 2005 2:57 pm
Posts: 16
In the org.hibernate.test.mapcompelem test case I modified the code to add a test for the index HQL function.
When I call the "from Product p where :partName in indices(p.parts)" query I have the expected results but
when I call the "from Product p where :partName = index(p.parts)" query, I get the following error:

org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.test.mapcompelem.MapCompositeElementTest.testMapCompositeElementWithFormula(MapCompositeElementTest.java:57)
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 junit.framework.TestCase.runTest(TestCase.java:154)
at org.hibernate.test.TestCase.runTest(TestCase.java:129)
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:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: java.sql.SQLException: Column not found: PARTS1_.PARTNAME in statement [select product0_.productName as productN1_ from Products product0_ where (?=parts1_.partName)]
at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:351)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:302)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:85)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1090)
at org.hibernate.loader.Loader.doQuery(Loader.java:362)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 22 more

The modified test case is:
Code:
//$Id: MapCompositeElementTest.java,v 1.3 2005/02/21 14:41:01 oneovthafew Exp $
package org.hibernate.test.mapcompelem;

import java.util.List;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.test.TestCase;

/**
* @author Gavin King
*/
public class MapCompositeElementTest extends TestCase {
   
   public MapCompositeElementTest(String str) {
      super(str);
   }
   
   public void testMapCompositeElementWithFormula() {
      Session s = openSession();
      Transaction t = s.beginTransaction();
      Part gavin = new Part("top", "The top part");
      Part turin = new Part("bottom", "The bottom part");
      Product g = new Product("Some Thing");
      g.getParts().put("Top", gavin);
      g.getParts().put("Bottom", turin);
      s.persist(g);
      t.commit();
      s.close();
      
      s = openSession();
      t = s.beginTransaction();
      g = (Product) s.get(Product.class, "Some Thing");
      assertEquals( g.getParts().size(), 2 );
      g.getParts().remove("Bottom");
      t.commit();
      s.close();

      s = openSession();
      t = s.beginTransaction();
      g = (Product) s.get(Product.class, "Some Thing");
      assertEquals( g.getParts().size(), 1 );
      g.getParts().put("Top", new Part("top", "The brand new top part"));
      t.commit();
      s.close();

      s = openSession();
      t = s.beginTransaction();

      //Query query = s.createQuery("from Product p where :partName in indices(p.parts)");
      Query query = s.createQuery("from Product p where :partName = index(p.parts)");
      query.setString("partName", "Top");
      List result = query.list();
      assertEquals(1, result.size());
      assertTrue(result.get(0) instanceof Product);
      assertEquals("Some Thing",((Product) result.get(0)).getName());
      
      t.commit();
      s.close();

      s = openSession();
      t = s.beginTransaction();
      g = (Product) s.get(Product.class, "Some Thing");
      assertEquals( g.getParts().size(), 1 );
      assertEquals(  ( (Part) g.getParts().get("Top") ).getDescription(), "The brand new top part");
      s.delete(g);
      t.commit();
      s.close();
}
   
   protected String[] getMappings() {
      return new String[] { "mapcompelem/ProductPart.hbm.xml" };
   }

   public static Test suite() {
      return new TestSuite(MapCompositeElementTest.class);
   }

}



Hibernate version: 3.0 rc1

Mapping documents: see the org.hibernate.test.mapcompelem test case

Full stack trace of any exception that occurs: see above

Name and version of the database you are using: hssql

The generated SQL (show_sql=true):

select product0_.productName as productN1_ from Products product0_ where (?=parts1_.partName)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 1:27 pm 
Newbie

Joined: Mon Mar 14, 2005 2:57 pm
Posts: 16
I tested this again with hibernate 3.0 final and the problem still exists.

Is there a problem in my code? Can someone please verify if this is a hibernate issue or something is wrong with my code?


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.