-->
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.  [ 1 post ] 
Author Message
 Post subject: Custom Criterion passing values into XMLEXISTS clause
PostPosted: Mon Aug 15, 2011 6:29 am 
Beginner
Beginner

Joined: Sun Oct 09, 2005 3:21 pm
Posts: 40
Using Hibernate 3.6...

Building a query through the Criteria API. Mixing traditional SQL with XML in DB2 9.7 (same stuff works for Oralce, Postgresql) where the column housing the XML as an SQL type of XML. Compilation internal to DB2 for an XPATH XMLEXISTS clause takes over 50% of the total SQL execution time. If there is a high amount of XPATH statements that are the same differing only in comparison values the compilation becomes a problem. A XMLEXISTS clause gets recompiled if the values aren't treated as variables as int explicit casting.

So I have adjusted a Criterion class (i.e. "implements Criterion") for XPath to pull out all the comparison values and replace them with explicit casting. Added the values as Hibernate string types. But the resulting query is rejected with a SQLSTATE 2200M ("*SQLSTATE 2200M: A value failed to parse as a well-formed XML document*").

Without explicit casting the resulting SQL (i.e. as see by the IBM DB2 JDBC driver) is:
Code:
...XMLEXISTS (? PASSING THIS_.CONFIGURATION AS "THIS"))...


where CONFIGURATION is the XML column and the "?" placeholder is the entire XPATH statement.

With explicit casting in the Hibernate CriteriaQueryTranslator.getQueryParameters method the processed SQL is:
Code:
select count(*) as y0_
       from ELEMENT ...
       where XMLEXISTS('declare namespace sw="http://www.klistret.com/cmdb/ci/element/component/software";declare namespace pojo="http://www.klistret.com/cmdb/ci/pojo";$this/*[sw:Module = ($a)]' PASSING this_.CONFIGURATION AS "this", XMLCAST(? as XML) as "a") ....


And the positional type parameters are in the right order (obs. the entire statement isn't shown above but the parameters are of string and delimited correctly).

Is it that parameters "inside" a functional clause (XMLEXISTS) can't be set by Hibernate? My Criterion class is here.

One thing to note is that when not doing explicit casting the SQL according to Hibernate looks like:
Code:
select count(*) as y0_
       from ELEMENT ...
       where XMLEXISTS('declare namespace sw="http://www.klistret.com/cmdb/ci/element/component/software";declare namespace pojo="http://www.klistret.com/cmdb/ci/pojo";$this/*[sw:Module = ("KUI")]' PASSING this_.CONFIGURATION AS "this") ...


which is different than what is picked up by my monitor (Introscope) over what SQL is sent to DB2 being as above:
Code:
...XMLEXISTS (? PASSING THIS_.CONFIGURATION AS "THIS"))...


An explicit without trying to replace variables looks like:
Code:
...XMLEXISTS (? PASSING THIS_.CONFIGURATION AS "THIS", XMLCAST (? AS XML) AS "A"))...


So not 100% that "actual" SQL handed over to DB2 will be as fine grained as I would like namely:
Code:
...XMLEXISTS('declare namespace sw="http://www.klistret.com/cmdb/ci/element/component/software";declare namespace pojo="htt
p://www.klistret.com/cmdb/ci/pojo";$this/*[sw:Module = ($a)]' PASSING this_.CONFIGURATION AS "this", XMLCAST(? as XML) as "a")...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.