Re: Creating / Deleting an object == NullPointer

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Mar 26 2003 - 21:52:34 EST

  • Next message: Jason Bedell: "Can select "Dep PK""

    Hi Noel,

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

    Yes it should. This might be a bug. Let me verify that this happens in
    the current development version of the code, since we changed lots of
    internal DataContext wiring since the last alpha. I'll get back when I
    have some results.

    Andrus

    On Wednesday, March 26, 2003, at 09:41 PM, Noel Murphy wrote:

    >
    > 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(ExpressionF
    > actory.java:376)
    > at
    > org.objectstyle.cayenne.QueryHelper.deleteQuery(QueryHelper.java:158)
    > at
    > org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.ja
    > va: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:56:55 EST