Cannot override setPersistenceState in 3.0-M5

From: Bob Schellink (sabob..mail.com)
Date: Wed Jan 21 2009 - 06:53:26 EST

  • Next message: Andrey Razumovsky: "Re: Cannot override setPersistenceState in 3.0-M5"

    Hi all,

    Perhaps this is a known issue but there seems to be a slight
    regression in 3.0-M5 when overriding setPersistenceState.
    When invoking dataContext#newObject a NPE is thrown.

    The reason I want to override setPersistenceState is to set the
    inheritance type of the hierarchy. For example:

      public class Manager extends _Manager {

        public void setPersistenceState(int state) {
            super.setPersistenceState(state);

            if(state == PersistenceState.NEW) {
               setEmployeeType("MANAGER");
            }
        }
      }

    To test I use:

      public static void main(String[] args) {
        DataContext dc = DataContext.createDataContext();

        Employee emp = (Employee) dc.newObject(Manager.class); // <-- this
    call fails
        dc.commitChanges();
      }

    Stacktrace:

    Exception in thread "main" java.lang.NullPointerException
            at org.apache.cayenne.access.ObjectStore.registerDiff(ObjectStore.java:187)
            at org.apache.cayenne.access.ObjectStore.nodePropertyChanged(ObjectStore.java:1080)
            at org.apache.cayenne.util.ObjectContextGraphAction.handleSimplePropertyChange(ObjectContextGraphAction.java:83)
            at org.apache.cayenne.util.ObjectContextGraphAction.handlePropertyChange(ObjectContextGraphAction.java:67)
            at org.apache.cayenne.access.DataContext.propertyChanged(DataContext.java:1591)
            at org.apache.cayenne.CayenneDataObject.writeProperty(CayenneDataObject.java:226)
            at test.auto._Employee.setEmployeeType(_Employee.java:16)
            at test.Manager.setPersistenceState(Manager.java:13)
            at org.apache.cayenne.access.DataContext.newObject(DataContext.java:750)
            at org.apache.cayenne.access.DataContext.newObject(DataContext.java:715)
            at test.Test.main(Test.java:17)

    Should I open a JIRA for this?

    kind regards

    bob



    This archive was generated by hypermail 2.0.0 : Wed Jan 21 2009 - 07:01:35 EST