I'm getting the following error:
Code:
net.sf.hibernate.QueryException: in expected: i [from item i where ? in i.description]
at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1527)
at ftest.ItemRetrievalFTest.testRetrieveByFind(ItemRetrievalFTest.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
when I execute this method:
Code:
public void testRetrieveByFind() throws HibernateException {
Session session = getSession();
String query = "from item i where ? in i.description";
String value = "Old Guitar";
List results = session.find(query, value, new StringType());
assertNotNull(results);
assertTrue(results.size() > 0);
System.out.println("Size of Find list: " + results.size());
session.close();
}
Any ideas anyone?
Hibernate version:2.1:
Mapping documents:<hibernate-mapping>
<class name="domain.Item" table="item" dynamic-insert="true" dynamic-update="true" lazy="true">
<id name="id" unsaved-value="0" column="ITEM_ID" type="long">
<generator class="identity" />
</id>
<bag name="bids" cascade="all-delete-orphan" inverse="true">
<key column="ITEM_ID" />
<one-to-many class="domain.Bid" />
</bag>
<property name="description" type="java.lang.String" column="description" />
<property name="price" type="float" column="price" />
</class>
<class name="domain.Bid" table="bid" lazy="true">
<id name="id" unsaved-value="0" column="BID_ID" type="long">
<generator class="identity" />
</id>
<many-to-one name="item" column="ITEM_ID" class="domain.Item" />
<property name="amount" column="amount" type="float" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
String query = "from item i where ? in i.description";
String value = "Old Guitar";
List results = session.find(query, value, new StringType());
assertNotNull(results);
assertTrue(results.size() > 0);
System.out.println("Size of Find list: " + results.size());
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Hibernate: select item0_.ITEM_ID as ITEM_ID, item0_.description as descript2_, item0_.price as price from item item0_ where (item0_.description=? )
Hibernate: select bids0_.ITEM_ID as ITEM_ID__, bids0_.BID_ID as BID_ID__, bids0_.BID_ID as BID_ID0_, bids0_.ITEM_ID as ITEM_ID0_, bids0_.amount as amount0_ from bid bids0_ where bids0_.ITEM_ID=?
Hibernate: select bids0_.ITEM_ID as ITEM_ID__, bids0_.BID_ID as BID_ID__, bids0_.BID_ID as BID_ID0_, bids0_.ITEM_ID as ITEM_ID0_, bids0_.amount as amount0_ from bid bids0_ where bids0_.ITEM_ID=?
Hibernate: select item0_.ITEM_ID as ITEM_ID0_, item0_.description as descript2_0_, item0_.price as price0_ from item item0_ where item0_.ITEM_ID=?
Hibernate: select bids0_.ITEM_ID as ITEM_ID__, bids0_.BID_ID as BID_ID__, bids0_.BID_ID as BID_ID0_, bids0_.ITEM_ID as ITEM_ID0_, bids0_.amount as amount0_ from bid bids0_ where bids0_.ITEM_ID=?
Debug level Hibernate log excerpt: