Re: Help upgrading 3.0.2 code to 4.2.2

"[email protected]" <[email protected]> Sat, 4 Oct 2025 10:29:15 +0200
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CAAOOpAPyb-T6uOQcZvHj0=z6hz8QQCTjpSjrvT1b7QYaK9Djjw@mail.gmail.com>
Thanks Michael,
I now need to find how to rewire what I was previously doing mostly
using the org.apache.cayenne.conf package.
I suppose this is part of the friction I'll have to go through to get
a plain Jar (with Jetty).

Thanks for the pointer.

Giulio Cesare

On Wed, Oct 1, 2025 at 9:16=E2=80=AFPM Michael Gentry <[email protected]>=
 wrote:
>
> Hi Giulio,
>
> In 4.2, you get the ObjectContext from the Cayenne Runtime:
>
> https://cayenne.apache.org/docs/4.2/getting-started-guide/#getting-starte=
d-with-objectcontext
>
> mrg
>
> On Wed, Oct 1, 2025 at 5:23=E2=80=AFAM [email protected] <
> [email protected]> wrote:
>
> > Hello,
> > I have been able to fix almost all the warnings and errors.
> > I have to points that I am not able to fix, though:
> > - I was still using DataContext (instead of ObjectContext); is this
> > still a useful class? Otherwise, how do I create a DataContext, as
> > `DataContext.createDataContext();` is not defined
> > - how do I replace the use of ServletUtil.initializeSharedConfiguration=
?
> >
> > Thanks,
> > Giulio Cesare
> >
> > On Tue, Sep 30, 2025 at 3:50=E2=80=AFPM [email protected]
> > <[email protected]> wrote:
> > >
> > > Thanks Andrus!
> > >
> > > I'll report on any progress with my upgrade.
> > >
> > > Giulio Cesare
> > >
> > > On Tue, Sep 30, 2025 at 2:26=E2=80=AFPM Andrus Adamchik <aadamchik@gm=
ail.com>
> > wrote:
> > > >
> > > > Hi Giulio,
> > > >
> > > > SelectQuery is replaced with ObjectSelect. But in your case (a quer=
y
> > modeled in the DataMap), you would actually use something else - a
> > MappedSelect query per
> > https://cayenne.apache.org/docs/4.2/cayenne-guide/#mappedselect-and-map=
pedexec
> > > >
> > > > MappedSelect.query("attachment", Attachment.class)
> > > >     .param("reference", aReference)
> > > >     .param("user", anUser)
> > > >     .select(context);
> > > >
> > > > Thanks,
> > > > Andrus
> > > >
> > > >
> > > > > On Sep 30, 2025, at 3:15=E2=80=AFAM, [email protected] wrot=
e:
> > > > >
> > > > > Hello everybody,
> > > > >
> > > > > even if this will force me to admit how old I am, I still have so=
me
> > > > > Cayenne 3.0.2 code happily running in production with no issues.
> > > > >
> > > > > Lately I was trying to upgrade the application from a WAR (runnin=
g in
> > > > > Tomcat) to a standalone application exposing the servlets via Jet=
ty,
> > > > > in order to make the application easier to deploy in a docker
> > > > > container.
> > > > >
> > > > > After some struggle to update the model, I am now facing a LOT of
> > > > > deprecation warnings like this:
> > > > >> [deprecation] SelectQuery in org.apache.cayenne.query has been
> > deprecated
> > > > >
> > > > > The code I have looks like this:
> > > > > -------------------
> > > > > prototypeQuery =3D
> > > > >
> > (SelectQuery)dataContext.getEntityResolver().lookupQuery("attachment");
> > > > >
> > > > > parameters =3D new HashMap();
> > > > > parameters.put("reference", aReference);
> > > > > parameters.put("user", anUser);
> > > > > query =3D prototypeQuery.queryWithParameters(parameters);
> > > > >
> > > > > result =3D (List<Attachment>)dataContext.performQuery(query);
> > > > > -------------------
> > > > >
> > > > > Unfortunately I never had the opportunity to use any newer versio=
n of
> > > > > Cayenne, so I haven't followed along with all the changes that it=
 has
> > > > > gone through.
> > > > >
> > > > > Is there anyone willing to suggest me what the above code snippet
> > > > > would look like with the new version of Cayenne?
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Giulio Cesare
> > > >
> >