M
M
MaxLich2019-12-18 17:53:42
Java
MaxLich, 2019-12-18 17:53:42

How to select a list of entities with a custom set of attributes via the Criteria API if the entity has an associated collection of other entities?

Hello. There is an entity in which one of the fields is a collection of other entities:

class UserEntity {
private Long id;
private String name;
private Set<GroupEntity> groups;
private byte[] avatar;
//....
}

It is necessary to get a list of these users via Criteria API, and not all fields need to be selected (one field must be excluded - avatar). But the field with the collection of entities must be included in the selection.
I searched on the Internet - I did not find it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mayton2019, 2019-12-22
@mayton2019

The question is not clear. If CriteriaApi can get a stream of arbitrary objects (UserEntity), then
you can always apply the map method to the stream and take only the required stream of fields.

.stream().map(userEntity -> userEntity.getAvatar)....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question