Re: Is registerNewObject required?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Dec 07 2005 - 11:54:48 EST

  • Next message: Tore Halset: "[OT] a map with all the users?"

    Dave,

    Relationships in Cayenne will only work for registered objects. So if
    you application requires non-persistent objects, don't extend
    CayenneDataObject at all - this doesn't buy you anything, and only
    creates problems that you are seeing.

    Expression.evaluate() and Expression.filterObjects() will work with
    any Java bean, DataObject or not. But the rest of Cayenne depends on
    the fact that the objects are (a) mapped in the Modeler and (b)
    registered with a DataContext.

    Andrus

    On Dec 7, 2005, at 6:10 PM, Dave Merrin wrote:
    > Hi,
    >
    > I'm trying to use cayenne to perform some queries on an in-memory
    > list. The
    > list of objects hasn't been loaded from a database using cayenne,
    > it has
    > just been created from some arbitrary data. All this was working fine.
    >
    > Now I've discovered my data doesn't represent just one type of
    > object, it
    > represents many related objects. As an example I have a
    > TrackMessage object
    > which now needs to have a related UniqueID object. Both classes extend
    > CayenneDataObject. Now when I call setToOneTarget passing in a created
    > MessageID I get the following exception:
    >
    > java.lang.NullPointerException
    > at
    > org.objectstyle.cayenne.CayenneDataObject.getRelationshipNamed
    > (CayenneDataOb
    > ject.java:400)
    > at
    > org.objectstyle.cayenne.CayenneDataObject.setToOneTarget
    > (CayenneDataObject.j
    > ava:343)
    > at
    > ipa.printexpress.tracker.logfilter.TrackMessage.setInstanceID
    > (TrackMessage.j
    > ava:132)
    > at
    > ipa.printexpress.tracker.logfilter.TrackMessage.<init>
    > (TrackMessage.java:73)
    > at
    > ipa.printexpress.tracker.logfilter.MessageRouter.run
    > (MessageRouter.java:35)
    > at
    > ipa.printexpress.tracker.logfilter.ThreadPoolWorker.runIt
    > (ThreadPoolWorker.j
    > ava:101)
    >
    > I'm sure the last time I saw this I needed to register the objects
    > using
    > DataContext.registerNewObject. The only thing is I don't have a
    > DataContext
    > and don't particulary want one (because none of this is related to a
    > database connection).
    >
    > Is there any way round this problem? If I do have to create a
    > DataContext
    > object then does it have to actually be connected to a database? Do
    > I need
    > to tell the DataContext about the relationship of the objects?
    >
    > Any help would be greatly appreciated. I'm still hoping I can pull
    > off this
    > alternative way of using cayenne.
    >
    > Cheers,
    >
    > Dave
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Dec 07 2005 - 11:54:55 EST