Re: Help upgrading 3.0.2 code to 4.2.2

Michael Gentry <[email protected]> Wed, 1 Oct 2025 14:55:22 -0400
Newsgroups gmane.comp.java.cayenne.user
Message-ID <CAOy5kzP9KHar-9gJeTQR+_aY2iFSWH65OqGajMWckYR5+uABzQ@mail.gmail.com>
--0000000000004ab6f606401d6bb6
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Giulio,

In 4.2, you get the ObjectContext from the Cayenne Runtime:

https://cayenne.apache.org/docs/4.2/getting-started-guide/#getting-started-=
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@gmai=
l.com>
> wrote:
> > >
> > > Hi Giulio,
> > >
> > > SelectQuery is replaced with ObjectSelect. But in your case (a query
> 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-mappe=
dexec
> > >
> > > 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] wrote:
> > > >
> > > > Hello everybody,
> > > >
> > > > even if this will force me to admit how old I am, I still have some
> > > > Cayenne 3.0.2 code happily running in production with no issues.
> > > >
> > > > Lately I was trying to upgrade the application from a WAR (running =
in
> > > > Tomcat) to a standalone application exposing the servlets via Jetty=
,
> > > > 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 version =
of
> > > > Cayenne, so I haven't followed along with all the changes that it h=
as
> > > > 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
> > >
>

--0000000000004ab6f606401d6bb6--