Re: NullPointerException

From: Mike Kienenberger (mkienen..laska.net)
Date: Tue Aug 17 2004 - 13:50:55 EDT

  • Next message: Gowry Gabriev: "Re: NullPointerException"

    Gowry Gabriev <gowry.gabrie..mail.com> wrote:
    > I modified UpdateBatchQueryBuilder createSqlString to ignore null
    > dbattribute entries, and it seems to be working for me so far. I tried
    > to find the previous versions on sourceforge cvs to see if it'd changed
    > recently but the file didn't exist there.

    >From what you've got below, UpdateBatchQueryBuilder hasn't changed since
    post-optimistic-locking.
    However, the code that populates the updateBatch.getUpdatedAttributes()
    might have changed.

    But as you've noticed, public cayenne cvs access isn't currently available.

    It's really odd that updatedDbAttributes would contain null dbAttributes.
    Can you tell us more about your environment? What database driver you're
    using? Whether you're using optimistic locking or not? Can you post your
    data map? Can you also provide the bad query string being generated?

    It'd really be best to open this as an issue in the cayenne bug tracker.
    Otherwise, your patch may not get applied. It will also make it easier to
    have a central location to store the answers for these questions for each
    user who is having this problem so we can detect any common elements. I've
    been using this UpdateBatchQueryBuilder code for months without any
    problems, but I only use OpenBase/Oracle and full optimistic locking.

    -Mike

    > public String createSqlString(BatchQuery batch) {
    > UpdateBatchQuery updateBatch = (UpdateBatchQuery) batch;
    > String table = batch.getDbEntity().getFullyQualifiedName();
    > List qualifierAttributes = updateBatch.getQualifierAttributes();
    > List updatedDbAttributes = updateBatch.getUpdatedAttributes();
    >
    > StringBuffer query = new StringBuffer("UPDATE ");
    > query.append(table).append(" SET ");
    >
    > int len = updatedDbAttributes.size();
    > for (int i = 0; i < len; i++) {
    > if(updatedDbAttributes.get(i)!=null) {
    > if (i > 0) {
    > query.append(", ");
    > }
    >
    > DbAttribute attribute = (DbAttribute)
    > updatedDbAttributes.get(i);
    > query.append(attribute.getName()).append(" = ?");
    > }
    > }
    >
    > query.append(" WHERE ");
    >
    > Iterator i = qualifierAttributes.iterator();
    > while (i.hasNext()) {
    > DbAttribute attribute = (DbAttribute) i.next();
    > appendDbAttribute(query, attribute);
    > query.append(updateBatch.isNull(attribute) ? " IS NULL" : " =
    ?");
    >
    > if (i.hasNext()) {
    > query.append(" AND ");
    > }
    > }
    >
    > return query.toString();
    > }
    >
    >
    > On Tue, 17 Aug 2004 10:54:45 -0400, Mike Kienenberger
    > <mkienen..laska.net> wrote:
    > > It's also possible it's related to optimistic locking, for which I did
    the
    > > peliminary code in UpdateBatchQueryBuilder back in M3/M4/M5.
    Unfortunately,
    > > I didn't see the original message, only the message that Andrus
    responded
    > > to.
    > >
    > > I was unable to grab 1.1b2 from cvs yesterday, but I'll try again today
    and
    > > see if anything is obviously wrong to me.
    > >
    > > Please open a support case and attach any relevant information,
    including
    > > stack traces and your use of optimistic locking.
    > >
    > > Thanks!
    > >
    > > -Mike
    > >
    > >
    > >
    > >
    > > Gary Jarrel <garyjarre..rownbilljarrel.com.au> wrote:
    > > > It's quite interesting that somebody mentioned this issue cause I'm
    > > getting
    > > > an exactly the same problem with 1.1B2 over the last few days. I
    haven't
    > > > tested with a previous beta version.
    > > >
    > > > But now that Andrus mentioned some interesting facts about the db
    > > > relationships I might start looking from that angle a bit closer.
    > > >
    > > > Whats funny, was that I thought it was my SQL server driver issue, as
    I
    > > was
    > > > using the MS jdbc driver. I've switched to using the jdts driver and
    it
    > > > worked once ok but then started throwing the exception again. Hmm will
    > > keep
    > > > looking.
    > > >
    > > > - Gary
    > > >
    > > > -----Original Message-----
    > > > From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    > > > Sent: Monday, August 16, 2004 7:10 PM
    > > > To: cayenne-use..bjectstyle.org
    > > > Subject: Re: NullPointerException
    > > >
    > > > Hmm, that's strange. Could you submit a bug report
    > > > (http://objectstyle.org/cayenne/bugs-features.html), attaching your
    data
    > > > map and sample code.
    > > >
    > > > A random question - when you save your project in the modeler, do you
    get
    > > > any warnings?
    > > >
    > > > P.S. As I am still on vacation, I won't be able to do any real work on
    > > > that till the end of August.
    > > >
    > > > > I'm getting a NullPointerException when I'm running a program.
    > > > > It occurs on line 97 of UpdateBatchQueryBuilder in 1.1B2.
    > > > >
    > > > > I looked at the data structures in a debugger, and it has 7
    > > > > null DbAttribute objects that it's attempting to do an update for.
    > > > >
    > > > > Have I done something wrong in my code or is there a bug here?
    > > > >
    > > > > Thanks!
    > > > >
    > > > > Gowry
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > >



    This archive was generated by hypermail 2.0.0 : Tue Aug 17 2004 - 13:50:49 EDT