Okay I am now trying to get the report query to work.

I use the following code:

          Iterator result = null;
        PersistenceBroker broker = null;

        try
        {
            broker = getBroker();
            Criteria criteria = new Criteria();
            criteria.addEqualTo("lastName", "Smith");

            ReportQueryByCriteria query = new
ReportQueryByCriteria(Person.class, criteria);

                /* i am using the names from the repository.xml that map to the 
columns in
the table
                   i asuume that is the value i am supposed to use when identifying the
columns
                */

                query.setColumns( new String[] {"id","firstName","lastName"});

            result = broker.getReportQueryIteratorByQuery(query);

            broker.close();
        }
        catch (PBFactoryException ex)
        {
            logger.debug(ex.getMessage(),ex.fillInStackTrace());
        }

        writer.println("<table border=\"1\">");

        while (result.hasNext())
        {
            Person person = (Person)result.next();
            writer.println("<tr>" +
                                        "<td>" + person.getId() + "</td>" +
                                        "<td>" + person.getFirstName() + "</td>" +
                                        "<td>" + person.getLastName() </td>" +
                                   "</tr>");
                                   );
        }

        writer.println("</table>");

when i do this i get a class cast exception and when i check to see if the
result.next() object is an instance of Person it says false. However the
iterator contains the proper amount of objects from the database that have
the last name Smith. Where did I go wrong and why is it not casting to the
Person object from the generic object. Followin is the exception:

StandardWrapperValve[TestServlet]: Servlet.service() for servlet TestServlet
threw exception
java.lang.ClassCastException: [Ljava.lang.Object;
        at TestServlet.writeReportTable(TestServlet.java:149)
        at TestServlet.doGet(TestServlet.java:93)
          39 more lines. These are all that matter....

Brandon Goodin
Phase Web and Multimedia
P (406) 862-2245
F (406) 862-0354
[EMAIL PROTECTED]
http://www.phase.ws


> -----Original Message-----
> From: Jakob Braeuchi [mailto:[EMAIL PROTECTED]]
> Sent: Monday, September 02, 2002 12:24 PM
> To: OJB Users List
> Subject: Re: SELECT statements and OJB
>
>
> hi brandon,
>
> ojb does not support partial loading of business objects.
> if you only need ID, FIRSTNAME, LASTNAME you can either use a ReportQuery,
> or you define your special ListPerson class.
>
> hth
> jakob
>
> ----- Original Message -----
> From: "Phase Web and Multimedia" <[EMAIL PROTECTED]>
> To: "OJB Users List" <[EMAIL PROTECTED]>
> Sent: Monday, September 02, 2002 7:23 AM
> Subject: SELECT statements and OJB
>
>
> > I am extremely new to OJB. But something I was wondering regarding using
> the
> > PB API is whether or not you can select the particular field (attribute)
> you
> > want returned. For example, i have a sql statement like such SELECT ID,
> > FIRSTNAME, LASTNAME FROM PEOPLE WHERE ID=2. The PEOPLE table actually
> > contains the following fields: ID, FIRSTNAME, LASTNAME, ADDRESS, CITY,
> > STATE, ZIP, NOTES. In OJB PB it seems that all i can do is the
> equivalent
> of
> > SELECT * FROM PEOPLE WHERE... I don't want to select all (*) the fields
> > everytime. In the afformentioned sql statement i want to just produce a
> list
> > of People objects that have only the id, firstname and lastname
> variables
> > populated. Am i missing something or is this just not possible
> apart from
> > using a sql statement call from the PB API's QuerBySQL (if that
> would even
> > work cuz i haven't tested it). If i can't be selective about
> the data that
> > populates my People object then I will produce a lot of unecessary data
> > collection and population from the database to my objects. Especially if
> the
> > NOTES field can contain 250k of data (an exaggeration of course but the
> > point is there). The thing that attracted me to OJB was how
> easy it is to
> > code to a database with OO patterns. I hope the solution isn't something
> > that requires me to write some kind of extra class each time i want to
> limit
> > what is populated in my People class or require me to create a whole new
> > class to handle just the listing of the basic people info.
> >
> > Thanks,
> > Brandon Goodin
> > Phase Web and Multimedia
> > P (406) 862-2245
> > F (406) 862-0354
> > [EMAIL PROTECTED]
> > http://www.phase.ws
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
> >
>
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>


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

Reply via email to