Hibernate version:3.1beta1
Code between sessionFactory.openSession() and session.close():
Code:
HibernateCallback callback = new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.createQuery("select count(distinct specie) from Specie specie where specie.tradeNames like '%" + theTradeName + "%'");
query.setCacheable(true);
return query.uniqueResult();
}
};
Full stack trace of any exception that occurs:Code:
22:44:59,718 ERROR run ServiceInvokationThread:64 - Error executing invokation!!! :(
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select count(distinct specie0_.id) as col_0_0_ from Specie specie0_, Specie_TradeName tradenames1_, TradeName tradename2_ where specie0_.id=tradenames1_.Specie_id and tradenames1_.tradeNames_id=tradename2_.id and (. like '%%')]; SQL state [37000]; error code [-11]; Unexpected token: . in statement [select count(distinct specie0_.id) as col_0_0_ from Specie specie0_, Specie_TradeName tradenames1_, TradeName tradename2_ where specie0_.id=tradenames1_.Specie_id and tradenames1_.tradeNames_id=tradename2_.id and (. like '%%')]; nested exception is java.sql.SQLException: Unexpected token: . in statement [select count(distinct specie0_.id) as col_0_0_ from Specie specie0_, Specie_TradeName tradenames1_, TradeName tradename2_ where specie0_.id=tradenames1_.Specie_id and tradenames1_.tradeNames_id=tradename2_.id and (. like '%%')]
java.sql.SQLException: Unexpected token: . in statement [select count(distinct specie0_.id) as col_0_0_ from Specie specie0_, Specie_TradeName tradenames1_, TradeName tradename2_ where specie0_.id=tradenames1_.Specie_id and tradenames1_.tradeNames_id=tradename2_.id and (. like '%%')]
at org.hsqldb.jdbc.Util.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:395)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1503)
at org.hibernate.loader.Loader.doQuery(Loader.java:638)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
at org.hibernate.loader.Loader.doList(Loader.java:1959)
at org.hibernate.loader.Loader.list(Loader.java:1928)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:405)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:293)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:862)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:630)
at com.thewoodexplorer.dal.impl.SpecieDaoImpl$4.doInHibernate(SpecieDaoImpl.java:140)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:356)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:329)
at com.thewoodexplorer.dal.impl.SpecieDaoImpl.getSpeciesByTradeNameCount(SpecieDaoImpl.java:144)
at com.thewoodexplorer.service.impl.SpecieServiceImpl.getSpeciesByTradeNameCount(SpecieServiceImpl.java:583)
at com.thewoodexplorer.service.impl.ServiceFacadeImpl$8.run(ServiceFacadeImpl.java:274)
at com.thewoodexplorer.service.ServiceInvokationThread$1.run(ServiceInvokationThread.java:59)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Name and version of the database you are using:HSQL-1.8.0.1
The generated SQL (show_sql=true):Code:
select count(distinct specie0_.id) as col_0_0_ from Specie specie0_, Specie_TradeName tradenames1_, TradeName tradename2_ where specie0_.id=tradenames1_.Specie_id and tradenames1_.tradeNames_id=tradename2_.id and (. like '%%')
Specie has a many-to-many relationship to TradeName. Because of this I need to use distinct; otherwise if 2 tradenames of a Specie match the like criteria they will be returned twice.
Any hint will be very appreciated.
Thanks