-->
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.  [ 3 posts ] 
Author Message
 Post subject: Vanishing comma in sql
PostPosted: Tue Oct 04, 2005 11:44 am 
Beginner
Beginner

Joined: Tue Nov 02, 2004 1:34 pm
Posts: 45
Hibernate version: 3.05

I have the following sql string:


Code:
INFO  - [NDDMetricService.getMetricBrowseFields] query: SELECT distinct new com.sbc.netrics.struts.database.NddMetric( NddMetric.metricId, NddMetric.metricNumber,NddMetric.metricName,NddMetric.metricDescription,NddMetric.dataSteward)  FROM  com.sbc.netrics.struts.database.NddMetric NddMetric  WHERE large_xml <> 'Y' AND extract(xml_doc , '/metric_extended_attributes/*') like  '%BUILD%'  order by metric_name ASC


Which yields the following debug:

Code:
Hibernate: select * from ( select distinct nddmetric0_.METRIC_ID as col_0_0_, nddmetric0_.METRIC_NUMBER as col_1_0_, nddmetric0_.METRIC_NAME as col_2_0_, nddmetric0_.METRIC_DESCRIPTION as col_3_0_, nddmetric0_.DATA_STEWARD as col_4_0_ from NDD_METRIC nddmetric0_ where large_xml<>'Y' and (extract(xml_doc '/metric_extended_attributes/*')like '%BUILD%') order by metric_name ASC ) where rownum <= ?


And the following errors:

Code:
WARN  - [JDBCExceptionReporter.logExceptions] SQL Error: 907, SQLState: 42000
ERROR - [JDBCExceptionReporter.logExceptions] ORA-00907: missing right parenthesis


Notice that the "," in "extract(xml_doc , '/metric_extended_attributes/*')" dissapears when the hibernate sql is displayed: "extract(xml_doc '/metric_extended_attributes/*')like '%BUILD%')"

which is likely the reason I'm getting an unbalanced paranthesis error. Why is hibernate parsing out the "," -- and HOW do I overcome this?

My tableService method:

Code:
   public List getMetricBrowseFields(int pageSize
                                  , int pageStart
                            , String orderByField
                            , String orderDirection
                            , String filterExpr) throws Exception
   {
      List nddMetricList;
      try {
         String sql = "SELECT distinct new com.sbc.netrics.struts.database.NddMetric( NddMetric.metricId," +
                      " NddMetric.metricNumber,NddMetric.metricName,NddMetric.metricDescription,NddMetric.dataSteward) " +
                      " FROM  com.sbc.netrics.struts.database.NddMetric NddMetric ";
         if (! filterExpr.equals("")) {
            filterExpr = "large_xml <> 'Y' AND " + filterExpr;
            log.info("filterX3: " + filterExpr);
            sql = sql + " WHERE " + filterExpr + " ";
            log.info("sql: " + sql);
         }
         sql = sql + " order by " + orderByField + " " + orderDirection;
         Query query = HibernateUtil3.getCurrentSession().createQuery(sql);
         query.setFirstResult(pageStart);
         query.setMaxResults(pageSize);
         query.setReadOnly(true);
         log.info("query: " + query.getQueryString());
         nddMetricList = query.list();
         
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      }
         
      return nddMetricList;

   }


Lee


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 5:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is happening because HIbernate is assuming that extract() refers to the ANSI SQL standard extract(day from ...) function. If you want to use the MySQL function, you need to register a SQLFunction in your own subclass of MySQLDIalect.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 9:53 am 
Beginner
Beginner

Joined: Tue Nov 02, 2004 1:34 pm
Posts: 45
gavin wrote:
This is happening because HIbernate is assuming that extract() refers to the ANSI SQL standard extract(day from ...) function. If you want to use the MySQL function, you need to register a SQLFunction in your own subclass of MySQLDIalect.


Ah....it's oracle, but I assume the solution is the same. Thanks.

Lee


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.