db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adam.s.allga...@exxonmobil.com
Subject Re: addAscendingOrderByColumn method not working
Date Tue, 22 Mar 2005 21:11:42 GMT
Try changing these:

            private static final String
SORT_ENTITY_TYPE_COL="PersonRolePeer.PERSON_REL_ENTITY_TYPE";
             private static final String
SORT_ENTITIY_ID_COL="PersonRolePeer.PERSON_REL_ENTITIY_ID";
             private static final String
SORT_ENTITY_NAME_COL="PersonRolePeer.PERSON_REL_ENTITY_NAME";
             private static final String
SORT_ROLE_DESC="PersonRolePeer.PERSON_REL_REL_DESC";


to this (remove all the ") :

            private static final String
SORT_ENTITY_TYPE_COL=PersonRolePeer.PERSON_REL_ENTITY_TYPE;
             private static final String
SORT_ENTITIY_ID_COL=PersonRolePeer.PERSON_REL_ENTITIY_ID;
             private static final String
SORT_ENTITY_NAME_COL=PersonRolePeer.PERSON_REL_ENTITY_NAME;
             private static final String
SORT_ROLE_DESC=PersonRolePeer.PERSON_REL_REL_DESC;

This will guarantee that you are using the generated table.column_name
strings.

Adam




                                                                                         
                                    
                      Katherine Stone                                                    
                                    
                      <kathyastone@gmail.co          To:      torque-user@db.apache.org
                                      
                      m>                             cc:                              
                                       
                                                     Subject: addAscendingOrderByColumn method
not working                    
                                                                                         
                                    
                      03/22/05 03:02 PM                                                  
                                    
                      Please respond to                                                  
                                    
                      "Apache Torque Users                                               
                                    
                      List"                                                              
                                    
                                                                                         
                                    
                                                                                         
                                    



Using Torque 3.0

Hello,
I have read over the various posts concerning
addDescendingOrderByColumn method not working when building a Criteria
object. If I do not include the addDescendingOrderByColumn or
addAscendingOrderByColumn, the sql works fine(but does not order of
course). When I add it back, a NullPointerException is thrown when
doSelect() is executed.
The column I am sorting on is a String. I noticed when stepping
through in debug mode, right after the
criteria.add(PersonRolePeer.PERSON_REL_PER_ID, getId()); , the
Criteria object inspection correctly prints out a select statement,
but after executing the addAscendingOrderByColumn line, the criteria
select statement seems blank.

Per the past posts:
I checked and the db name is set in the schema.xml. The db adapter is
also correct in the torque.properties file.

As you can see, in the commented out code , I tried a work around of a
custom criteria which I didn't get working yet either. I'd really like
to use the torque method though instead of a custom criteria. Any
ideas?
Thanks,
Kathy Stone

========schema.xml table entry=========
   <table name="PERSON_REL_VW" javaName="PersonRole">
             <column name="PERSON_REL_ID" type="DECIMAL"
javaName="RoleId"/>
             <column name="PERSON_REL_PER_ID" size="10" type="INTEGER"
javaName="ParentId"/>
             <column name="PERSON_REL_ENTITIY_ID" size="10" type="INTEGER"
javaName="ChildId"/>
             <column name="PERSON_REL_ENTITY_TYPE" size="17" type="VARCHAR"
javaName="ChildEntityType"/>
             <column name="PERSON_REL_ENTITY_NAME" size="64" type="VARCHAR"
javaName="ChildName"/>
             <column name="PERSON_REL_REL_DESC" size="64" type="VARCHAR"
javaName="RoleDesc"/>
    </table>
=====String defs and relevant method in Person.java=====
             private static final String
SORT_ENTITY_TYPE_COL="PersonRolePeer.PERSON_REL_ENTITY_TYPE";
             private static final String
SORT_ENTITIY_ID_COL="PersonRolePeer.PERSON_REL_ENTITIY_ID";
             private static final String
SORT_ENTITY_NAME_COL="PersonRolePeer.PERSON_REL_ENTITY_NAME";
             private static final String
SORT_ROLE_DESC="PersonRolePeer.PERSON_REL_REL_DESC";
             /*private static final String
SORT_ENTITY_TYPE_COL="PERSON_REL_ENTITY_TYPE";
             private static final String
SORT_ENTITIY_ID_COL="PERSON_REL_ENTITIY_ID";
             private static final String
SORT_ENTITY_NAME_COL="PERSON_REL_ENTITY_NAME";
             private static final String
SORT_ROLE_DESC="PERSON_REL_REL_DESC";*/
.........
             public List getRels(String sortOrder, String sortCol) throws
TorqueException{

                         List relList=null;
                         Criteria criteria = new Criteria();

                         String sortColName = SORT_ENTITY_TYPE_COL;
                         if (sortCol.equalsIgnoreCase("EntityType"))
                                     sortColName = SORT_ENTITY_TYPE_COL;
                         else if(sortCol.equalsIgnoreCase("RelatedTo"))
                                     sortColName = SORT_ENTITIY_ID_COL;
                         else if(sortCol.equalsIgnoreCase("Description"))
                                     sortColName = SORT_ENTITY_NAME_COL;
                         else if(sortCol.equalsIgnoreCase("Relationship"))
                                     sortColName = SORT_ROLE_DESC;

                                     //String sortOrderStrAsc = "ORDER BY "
+ sortColName + " ASC";
                                     //String sortOrderStrDesc = "ORDER BY
" + sortColName + " DESC";


                         if(sortOrder.equalsIgnoreCase("A")){

criteria.add(PersonRolePeer.PERSON_REL_PER_ID, getId());

//criteria.add(PersonRolePeer.PERSON_REL_PER_ID,(Object)sortOrderStrAsc,
Criteria.CUSTOM);
                                     //addAscendingOrderByColumn throws
null pointer exception... ugh

criteria.addAscendingOrderByColumn(sortColName);
                                     relList =
PersonRolePeer.doSelect(criteria);
                         }else
                         {

criteria.add(PersonRolePeer.PERSON_REL_PER_ID, getId());

criteria.addDescendingOrderByColumn(sortColName);

//criteria.add(PersonRolePeer.PERSON_REL_PER_ID,(Object)sortOrderStrDesc,
       Criteria.CUSTOM);
                                     relList =
PersonRolePeer.doSelect(criteria);
                         }
                         return relList;

             }

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message