Creating / Deleting an object == NullPointer

From: Noel Murphy (bnmurph..ogers.com)
Date: Wed Mar 26 2003 - 21:41:00 EST

  • Next message: Andrus Adamchik: "Re: Creating / Deleting an object == NullPointer"

    I'll start off by saying that I am very new to Cayenne.

    I have started an extremely simple contacts stand alone app that stores
    the contacts in a mysql DB.

    When the user creates a new Contact, and then "saves" the entry, I
    perform the following to register the object with the DataContext.

    if (contact != null && contact.getPersistenceState() ==
    PersistenceState.TRANSIENT) {
            m_context.registerNewObject(contact);
    }

    Now if the user deletes a contact I run the following code to delete the
    object from the DataContext

    if (contact != null) {
            m_context.deleteObject(contact);
    }

    Now when the application closes, the very last thing that is done is:

    void commitChanges() {
    if (m_context.hasChanges()) {
            m_context.commitChanges(Level.WARN);
    }
    }

    This all seems correct to me. However, if the user creates a contact and
    then deletes the contact in the same session, I get the following error
    (From Eclipse)

    java.lang.NullPointerException
            at
    org.objectstyle.cayenne.exp.ExpressionFactory.matchAllDbExp(ExpressionFactory.java:376)
            at
    org.objectstyle.cayenne.QueryHelper.deleteQuery(QueryHelper.java:158)
            at
    org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:815)
            at .rolodex.Rolodex.saveAllChanges(Rolodex.java:83)
            at (Rest has been removed..Just had to do with the window
    closing events, etc.)

    Shouldn't the DataContext/ObjectGraph be able to detect that a
    registered but uncommited object has been deleted or am I doing
    something wrong?

    Noel Murphy



    This archive was generated by hypermail 2.0.0 : Wed Mar 26 2003 - 21:45:24 EST