cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikita Timofeev <ntimof...@objectstyle.com>
Subject Re: ColumnSelect and to-many relationships
Date Fri, 26 May 2017 11:45:34 GMT
Hi Hugi,

You remembering this correctly, this was possible in 4.0M5.
Since 4.0.M6 there is API to select whole objects via column select.
It is working by default for toOne relationships,
for collections there is new method in Property flat(Class<?>), that
will return "flat" array of objects.

So your code should be like this:

List<Object[]> list = ObjectSelect
                        .query( Receipt.class )
                        .columns( Receipt.UNIQUE_ID,
Receipt.ENTRIES.flat(Entry.class) )
                        .where( Receipt.USER.dot( User.NAME ).eq(
"Hugi Þórðarson" ) )
                        .select( StrimillinnCore.newContext() );

But still Exception you got is incorrect, you supposed to get readable
message on how to use toMany relationships in ColumnSelect.
Could you please tell how property Receipt.ENTRIES is defined in the code?

On Fri, May 26, 2017 at 2:03 PM, Hugi Thordarson <hugi@karlmenn.is> wrote:
> Hi all,
> I seem to recall that it was possible to fetch to-many relationships using ColumnSelect.
However, if I attempt to do something like this…
>
> public static void main( String[] args ) {
>         List<Object[]> list = ObjectSelect
>                         .query( Receipt.class )
>                         .columns( Receipt.UNIQUE_ID, Receipt.ENTRIES )
>                         .where( Receipt.USER.dot( User.NAME ).eq( "Hugi Þórðarson"
) )
>                         .select( StrimillinnCore.newContext() );
>
>         for( Object[] row : list ) {
>                 System.out.println( Arrays.asList( row ) );
>         }
> }
>
> …the fetch will fail with a ClassCastException ([Ljava.lang.Object; cannot be cast
to org.apache.cayenne.DataRow).
>
> Any other way to do it? Or am I misremembering that this was possible?
>
> Cheers,
> - hugi



-- 
Best regards,
Nikita Timofeev

Mime
View raw message