You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Stephen Ting <st...@shinyang.com.my> on 2002/12/23 04:26:09 UTC

Some error in ORDER BY clause

 
I upgrade to OJB 0.9.8 recently and found the following error in ORDER
BY clause appear. Before upgrade, it's run without any problems in
version 0.9.5. 
 
Could anyone tell me what's the problems?
 
[org.apache.ojb.broker.accesslayer.JdbcAccess] ERROR: SQLException
during the execution of the SQL query: Column name brand.brand_make is
invalid in the ORDER BY clause because it is not contained in an
aggregate function and there is no GROUP BY clause.
Column name 'brand.brand_make' is invalid in the ORDER BY clause because
it is not contained in an aggregate function and there is no GROUP BY
clause.

 
        String sql = "SELECT brand_make FROM brand ORDER BY brand_make
ASC";                              
        ******* if i change the above sql to the below one, this error
will disappear.
         String sql = "SELECT brand_make FROM brand ORDER BY 1 ASC";

 
        Query query = QueryFactory.newQuery(BrandBO.class, sql);  
 
        Collection object = null;
        PersistenceBroker broker = null;
        try{
            //throw PBFactoryException
            broker = PersistenceBrokerFactory.createPersistenceBroker(
                    new PBKey("repository.xml" , null, null));
            
            object = broker.getCollectionByQuery(query); //throw
persistencebrokerexception
            //return back cascade retrieval to original state
            
        }catch(PBFactoryException e){
            if(broker != null) broker.close();            
            throw new DatastoreException("Fail to connect to the
Database" + e.getMessage());             
        }
        catch(PersistenceBrokerException e){
            if(broker != null) broker.close();            
            throw new DatastoreException("Fail to get the invoice from "
+ site.getName());            
        }
        finally{
            if(broker != null) broker.close();
        }                       
        return object;          
 
------------------------repository
-----------------------------------------------------
<class-descriptor
      class="my.com.shinyang.einout.business.bo.BrandBO"
      table="brand">
 
      <field-descriptor id="1"
         name="id"
         column="brand_make"
         jdbc-type="VARCHAR"
         primarykey="true"         
      />      
      
  </class-descriptor>
 
regards,
Stephen