Thanks a lot, Nikita! This is good stuff.

Tore.

> 18. sep. 2025 kl. 13:43 skrev Nikita Timofeev <[email protected]>:
> 
> Hi,
> 
> In Cayenne 4.2+ you could use PK properties for that, but you need to
> generate them first, as it's a new option in the cgen configuration.
> 
> Once you got them in your classes, you could use them to evaluate in
> memory:
> 
> Expression exp =
> Painting.TO_ARTIST.dot(Artist.ARTIST_ID_PK_PROPERTY).getExpression();
> // exp is just ExpressionFactory.dbIdPathExp("toArtist.ARTIST_ID") in case
> you can't run cgen
> Object id = exp.evaluate(painting);
> 
> as a bonus you could use these properties in queries to fetch FKs directly
> (Cayenne is smart enough in this case to not use join):
> 
> List<Long> ids = ObjectSelect.query(Painting.class)
>    .column(Painting.TO_ARTIST.dot(Artist.ARTIST_ID_PK_PROPERTY))
>    .select(context);
> 
> Hope this helps.
> 
> On Thu, Sep 18, 2025 at 12:38 PM Tore Halset <[email protected]> wrote:
> 
>> Hello.
>> 
>> With the following many-to-on relationship: Painting<<-->Artist. There is
>> an ARTIST_ID column in the PAINTING-table.
>> 
>> Having one Painting object, is it possible to get the ARTIST_ID value from
>> the painting row without fetching the Artist? Normally, I would just follow
>> the painting.getArtist().getId(), but for this case, I just want the artist
>> id for performance reasons.
>> 
>> I have tried to just map up artistId in the ObjEntity of Painting, but
>> that returned just null. I have also tried readPropertyDirectly, but do nok
>> know how to extract the ARTIST_ID from that.
>> 
>> - Tore.
> 
> 
> 
> -- 
> Best regards,
> Nikita Timofeev

Reply via email to