getResultList returning a list containing one object of null values rather than an empty list
See original GitHub issueDescription
We are querying for a list of sub views using the function EntityViewManager.applySetting(EntityViewSetting setting, CriteriaBuilder criteriaBuilder, String entityViewRoot)
. When these sub views exist in the db, we properly receive the results as a list. What we are having trouble with is when there aren’t any of these sub views in the db.
What we are doing:
CriteriaBuilder<Link.class> cb = cbf.create(em, Link.class).from(ClientProfile.class);
cb = cb.where("org.id").eq(orgId);
CriteriaBuilder<LinkView.class> linkBuilder = evm.applySetting(EntityViewSetting.create(LinkView.class), cb, "links");
return linkBuilder.getQuery().getResultList();
Expected behavior
Expected result when links exist on a client profile:
[{"url": "value", "name": "value"}]
Actual result when links exist on a client profile:
[{"url": "value", "name": "value"}]
Expected result when links do not exist on a client profile:
[]
Actual result when links do not exist on a client profile:
[{"url": "null", "name": "null"}]
Actual behavior
When there are no values in the db for the sub views we query for, we receive a result list with one element with null fields.
Steps to reproduce
As mentioned above, if we query for a list of sub views and none exist, we should see this behavior.
Provided the setup/query we are doing above.
Environment
Version: 1.6.5 JPA-Provider: Hibernate 5.4.32.Final (Spring Data JPA 2.4.13) DBMS: PostgreSQL 13.3 Application Server: Spring Boot 2.4.13
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
Oh, right, I was mixing up things. That won’t help when you use a sub path. Well, then your only way is to use the wrapper view for now.
Unfortunately, the only way to avoid the “empty object” for now, is to use a list index by annotating
@OrderColumn
on the entity collection. A possible alternative is to use a simple wrapper view: