Hi Felix,

I use DataContexts to group related changes.  If I need to do an
unrelated change, I create a new (or child) DataContext, do my change
in it, and commit it.  You don't have to stick to just one
DataContext.  Create as many as you need.

mrg


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.
>

Reply via email to