The thing to remember is that Cayenne DataContexts are completely under your control. There are convenience classes to automatically make one data context managed per session, but that's only one of many ways, not only way or even the recommended way.
It's hard to help without more specific information, but you could create a temporary one-time-use data context for your "some other object" below. Or you could create per-request data contexts, serialize the data objects you haven't finished with, and unserialize them into the next per-request data context. At least in 2.0, it was possible to serialize DataObjects (without the backing DataContext), and then reattach them to a new DataContext. Or you could have a session-scoped or application-scoped read-only context (by convention), then create a new data context whenever you wanted to make changes, and keep it around only as long as those changes were needed. On Wed, Apr 27, 2011 at 8:36 AM, felix <felix.serr...@technicalnorms.com> wrote: > I am using Cayenne with Wicket, and am using the servlet filter described > here > > http://cayenne.apache.org/doc30/web-applications.html > > to bind a DataContext to requests. I understand this occurs per session, so > subsequent > requests within the session are associated to the same DataContext, which is > fine. > > However, If I understand correctly, doing a commit against a DataContext > will persist _all_ > objects associated to that context. If for instance, I am using Cayenne > objects to accumulate > data, but I do not want to persist these objects (eg because they have not > reached a consistent > state) but I _do_ want to save some other object, then calling commit to > save this latter object will > save everything, including data that was not ready to be persisted. > > I am not sure exactly what pattern I should be using with Cayenne. Should > Cayenne objects be exposed > beyond the persistent layer? I am considering using a Data Transfer Object > pattern, whereby Cayenne > objects only exist at the data layer, and data is exposed to the rest of the > application via > data transfer objects, which are a parallel structure of POJO's. In the case > of Wicket, this has > the additional benefit of solving potential problems with serialization that > may have been a problem > with Cayenne objects. > > So, in summary, what is the correct usage of Cayenne? Is the DTO pattern I > have mentioned a reasonable > approach? > > If DTO is a good path, should I be using the 'cgen' maven task to generate > POJO's? I have searched for > suitable velocity templates to be used with the 'cgen' task but have found > none. Should I write my own > or is something planned within the Cayenne project along these lines? > > -- > View this message in context: > http://cayenne.195.n3.nabble.com/commit-all-objects-temporary-objects-POJO-s-DTO-tp2870230p2870230.html > Sent from the Cayenne - User mailing list archive at Nabble.com. >