Greetings,

  I was unsure where to post this (perhaps the developer list?), but 
decided here was as good as any.  I've uncovered a bug and am unsure what 
to attribute it to, so thought this would be a good forum.  I have worked 
around the problem, but hoped I could contribute something useful here.  
Please let me know if there is a better place to post this.

The problem:

   When executing a call to PersistenceBroker.getCollectionByQuery(query), 
where setStartAtIndex(1) has been called on query, a NullPointerException 
is thrown with the following stacktrace:

 Exception in thread "main" java.lang.NullPointerException
        at com.mysql.jdbc.ResultSet.getRow(ResultSet.java:1632)
        at org.apache.ojb.broker.accesslayer.RsIterator.size(Unknown 
 Source)
        at 
 org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
 Source)
        at 
 org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
 Source)
        at 
 org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
 Source)
        at 
 org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
 Source)
        at 
 
org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getCollectionByQuery(Unknown
 
 Source)
        at 
 edu.arizona.ltc.authentication.UserDAO.findAllUsers(UserDAO.java:168)
        at edu.arizona.ltc.authentication.UserDAO.main(UserDAO.java:199)

The problem is avoided by omitting the call to setStartAtIndex, or by 
setting startAtIndex to zero.  Certainly this is an off-by-one error, I 
thought.

HOWEVER!  If I ensure that there are multiple rows in the UserData table, 
this exception is still thrown.  I am writing because I believe there may 
be either a) an error in the MySQL driver and a related gap in error 
handling in RsIterator, or b) a flaw in the logic of RsIterator (perhaps 
a need to check the fetchSize of the ResultSet?).  [I am of course 
willing to consider c) I am doing something stupid and wrong... but I am 
certain that I will be corrected in this forum if that is the case ;) ]

Background (for anyone interested in the details):

I am developing a web application for the University of Arizona and have 
been using Wrox Press' "Professional Struts Applications; Building Web 
Sites with Struts, ObjectRelationalBridge, Lucene, and Velocity" (kudos to 
the authors - a good guide IMHO for web application and/or Apache Jakarta 
newbies).  I intend to use their example application as a template for the 
core of my application.

I am currently addressing the use of OJB to create a data access tier.  I 
originally intended to use postgresql beneath OJB but could never get the 
OJB tutorials to successfully run.  I switched to MySQL.  To start I have 
done a simple implementation of a user account system.  User information 
is in a table called UserData:

+----------------+--------------+------+-----+---------+-------+
| Field          | Type         | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| agent_id       | int(11)      |      | PRI | 0       |       |
| user_login     | varchar(20)  | YES  |     | NULL    |       |
| user_title     | varchar(5)   | YES  |     | NULL    |       |
| user_firstname | varchar(50)  | YES  |     | NULL    |       |
| user_lastname  | varchar(50)  | YES  |     | NULL    |       |
| user_email     | varchar(255) | YES  |     | NULL    |       |
| user_phone     | varchar(50)  | YES  |     | NULL    |       |
+----------------+--------------+------+-----+---------+-------+

UserData is mapped to an User class, with simple get/set methods for all 
of the above types.  Retrieving by primary key properly populates the User 
object, giving me confidence that I have appropriately configured 
repository_user.xml

UserDAO in the stacktrace above simply wraps the logic of aquiring a 
PersistenceBroker reference, creating Criteria and Query objects and 
executing transactions.  The code for findAllUsers() method is as follows 
(offending line has been commented out):

    public Collection findAllUsers() throws DataAccessException
    {
        PersistenceBroker broker = null;
        Collection results = null;
        
        try
        {
            Criteria crit = new Criteria();
            
            crit.addOrderByDescending ("user_login");
          
            Query query = QueryFactory.newQuery (User.class, crit);
            
           // query.setStartAtIndex (1);
            
            broker = ServiceLocator.getInstance().findBroker();
            
            results = (Collection) broker.getCollectionByQuery(query);
        }
        catch (ServiceLocatorException sle)
        {
            throw new DataAccessException 
                        ("Error in UserDAO.findAllUsers(): " + sle.getMessage(), sle);
        }
        finally
        {
            if (broker != null)
            {
                broker.close();
            }
        }
        
        return results;
    }

Thanks much,

Duffy

=====================================
Duffy Gillman
POLIS Systems Programmer

Learning Technology Center
PO Box 210073, CCIT Bldg., Rm. 337
1077 N. Highland Ave.
Tucson, AZ 85721-0073

520.626.0117 (voice)
520.626.8220 (fax)
=====================================


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to