Hi,
I’ve got some trouble, using a ValueCollection as Datasource for my screen.
Let me describe the Scenario:
*Object A
** Image
** other attributes
*Object B
** Many_to_one ObjectA
** other attributes
The datasource query looks like:
select b.objectA, b.attr, count(b.attr2)... from ObjectB b where b.year = 2018 ... GROUP BY b.objectA
That’s working fine.
But as soon as I try to access ObjectA.image I get a lazy initialization error.
Caused by: org.eclipse.persistence.exceptions.ValidationException: Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.
I tried to left join the ObjectA, works for the normal query, but access to ObjectA.image is not possible.
Since it’s a valueCollection, I tried to add ObjectA.image to the select statement, but it gives
java.sql.SQLSyntaxErrorException: expression not in aggregate or GROUP BY columns: T2.ID
(where T2.ID is image.ID)
I thought of adding a view to the ValueCollectionDS. So I created a view for ObjectB, containing ALL fields. But… It’s not possible to add the view to the VCDS via cuba Studio UI; I added it manually to the XML definition, but it doesn’t affect the behaviour.
So, long story short.
Is it possible to add a view to a ValueCollectionDataSource?
Or is it possible to retrieve the image via join? How? I even tried joining objectA.image, results in an empty resultset.
Or any other ideas to achieve my goal? (objectb data in a table, grouped by referenced objectA, showing the image of objectA, having some calculations performed in the query (therefore the VCDS and not a normal CollectionDS)
Thank you very much,
Kind regards,
Martin