Blazebit/blaze-persistence

Fetching entity view subset data with FetchStrategy.MULTISET issue

billysoderlund opened this issue · 2 comments

Description

I have an entity view with multiple properties using the MULTISET fetch strategy. If I only fetch some of these using the subset functionality on EntityViewSetting I get an exception. The SQL generated works as expected but it seems that the code tries to create a new instance of the excluded properties and fails because the query has not fetched them.

If I include all MULTISET properties it works, but that kind of defeats the purpose.

Expected behavior

Return objects for the selected path specified with "fetch(String path).

Actual behavior

Different exception depending on which MULTISET properties I include/exclude, e.g. class cast exception and index out of bounds.

java.lang.ClassCastException: class java.lang.Object cannot be cast to class java.util.List (java.lang.Object and java.util.List are in module java.base of loader 'bootstrap')
	at com.blazebit.persistence.view.impl.objectbuilder.transformer.MultisetTupleTransformer.transform(MultisetTupleTransformer.java:73) ~[blaze-persistence-entity-view-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.view.impl.objectbuilder.transformator.TupleTransformator.transform(TupleTransformator.java:84) ~[blaze-persistence-entity-view-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.view.impl.objectbuilder.transformator.TupleTransformator.transform(TupleTransformator.java:77) ~[blaze-persistence-entity-view-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.view.impl.objectbuilder.ChainingObjectBuilder.build(ChainingObjectBuilder.java:51) ~[blaze-persistence-entity-view-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.builder.object.PreProcessingObjectBuilder.build(PreProcessingObjectBuilder.java:46) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.builder.object.CountExtractionObjectBuilder.build(CountExtractionObjectBuilder.java:45) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.query.ObjectBuilderTypedQuery.getResultList(ObjectBuilderTypedQuery.java:71) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.PaginatedTypedQueryImpl.getResultList(PaginatedTypedQueryImpl.java:403) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.PaginatedTypedQueryImpl.getResultList(PaginatedTypedQueryImpl.java:218) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]
	at com.blazebit.persistence.impl.PaginatedCriteriaBuilderImpl.getResultList(PaginatedCriteriaBuilderImpl.java:613) ~[blaze-persistence-core-impl-jakarta-1.6.11.jar:1.6.11]

Environment

Version: 1.6.11
JPA-Provider: Spring Data JPA
DBMS: MySQL
Application Server: Spring Boot

Hi there and thanks for the report. Could you please share the entity and entity view model, as well as the list of fetches that you use so we can try to reproduce this, or even better, try to create a simple reproducer application e.g. based on our quickstarts? Just fyi, there might still be rough edges with MULTISET fetching when it comes to dynamic fetching.

Great, I used the spring boot quickstart and created a demo. Added two new actions, "/owners" and "/owners/subset". The subset action don't work. You will get an index out of bounds exception. If you change setting.fetch("kittens") to setting.fetch("kittensAgain") you will instead get a class cast exception.

demo.zip