-->
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: Incorrect binding of named parameters and filter parameters
PostPosted: Fri Sep 02, 2005 3:07 pm 
Newbie

Joined: Tue Jul 26, 2005 9:17 am
Posts: 4
Hibernate incorrectly binds named parameters when filter is enabled.

I have two classes: Issue and Comment. Both classes have the same filter defined in their mapping files:

Code:
<filter name="projectFilter" condition=":projectPK = PROJECT"/>

<filter-def name="projectFilter">
   <filter-param name="projectPK" type="java.lang.Long"/>
</filter-def>   


This HQL works fine:

Code:
select count(*) from Issue as i
where
   exists (from Comment c where c.PK = (select max(c2.PK) from Comment c2 where  c2.issue = i)) and
   i.text like :textParam


But almost the same HQL (only order of predicates in where clause is changed) generates error:

Code:
select count(*) from Issue as i
where
   i.text like :textParam and
   exists (from Comment c where c.PK = (select max(c2.PK) from Comment c2 where  c2.issue = i))



Code:
java.sql.SQLException
Error converting data type nvarchar to numeric.
SQLState: 37000
errorCode: 8114
Stack Trace:

* net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
* net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754)
* net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195)
* net.sourceforge.jtds.jdbc.TdsCore.isDataInResultSet(TdsCore.java:784)
* net.sourceforge.jtds.jdbc.JtdsResultSet.<init>(JtdsResultSet.java:143)
* net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:378)
* net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:672)
* org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
* org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137)
* org.hibernate.loader.Loader.getResultSet(Loader.java:1676)
* org.hibernate.loader.Loader.doQuery(Loader.java:662)
* org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
* org.hibernate.loader.Loader.doList(Loader.java:2147)
* org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
* org.hibernate.loader.Loader.list(Loader.java:2021)
* org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
* org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:296)
* org.hibernate.impl.SessionImpl.list(SessionImpl.java:985)
* org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
* org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:650)


Generated SQL from second HQL looks like this

Code:
select count(*) as col_0_0_ from ISSUE issue0_
where
   :projectFilter.projectPK = issue0_.PROJECT and
   (issue0_.TEXT like ?) and
   (exists (select comment1_.PK from COMMENT comment1_ where :projectFilter.projectPK = comment1_.project and comment1_.PK=(select max(comment2_.PK) from COMMENT comment2_ where :projectFilter.projectPK = comment2_.project and comment2_.ISSUE=issue0_.PK)))


Something gets broken with binding phase where named parameters and parameters from multiple filters are set. I believe that named parameters and filter parameters are mixed and bound in wrong order.
Hibernate bug?


Hibernate version: 3.0.5

Name and version of the database you are using: MS SQL Server


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Yes, this is a known bug with filters and subqueries, which is scheduled for fixing in 3.1 (the fix being not applying filters within subqueries).


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.