Thank you Nikita, that helps me. 

In EOF we use them in memory as well as for fetching from the database.

In Cayenne it seems that once I call exists() then the expression cannot be 
used for filtering in memory.

For example:

Expression expr = exp("paintings.name like 'S%'").exists();
                
List<Artist> someArtists = ObjectSelect
                .query(Artist.class)
                .where(expr)
                .select(context);

The above matches 1 artist, e.g. “Vincent Van Gogh” who has a paintings 
starting with the letter S, e.g. Starry Night and Sunflowers. But when I use 
that same expression against a list of all the artists like this:

List<Artist> someArtists2 = expr.filterObjects(allArtists);

Then someArtists2 is empty.

However, if I rewrite the code as follows:

Expression expr = exp("paintings.name like 'S%'");
                
List<Artist> someArtists = ObjectSelect
                .query(Artist.class)
                .where(expr.exists())
                .select(context);

// This matches 1 artist
List<Artist> someArtists2 = expr.filterObjects(allArtists);



Regards,
Ricardo Parada



> On Sep 27, 2025, at 12:26 PM, Nikita Timofeev <[email protected]> 
> wrote:
> 
> Hi Ricardo,
> 
> Yeah, there's not much info on that since that's a new API. `exists()` is a
> terminal operator that converts the whole expression to an EXISTS query.
> 
> So it would be something like this in your
> example: Artist.PAINTINGS.dot(Painting.NAME).like("painting%").exists()
> 
> 
> On Fri, Sep 26, 2025 at 8:31 PM Ricardo Parada <[email protected]>
> wrote:
> 
>> Hi all,
>> 
>> Another question I have is regarding EXISTS expressions.  I’m not sure if
>> I’m using the API correctly, but I was thinking it would be something like
>> this.  Using the entities from the Tutorial, let’s say I want to fetch the
>> Artist’s that have a painting starting with the letter ‘G’:
>> 
>> Expression e = Artist.PAINTINGS.exists(Painting.NAME.like(“G%”));
>> 
>> But I’m getting a syntax error.
> 
> 
> 
> -- 
> Best regards,
> Nikita Timofeev

Reply via email to