dzrkot
dzrkot

Reputation: 603

Find by list or field together by Spring Data

There is some class which contains userEntityList and field "author" type of UserEntity. I use hibernate and Spring Data. When I write method findAllByUserEntityList(UserEntity user) or method findAllByAuthor(UserEntity user) it works properly, but doesn't work if I try do this: findAllByUserEntityListOrAuthor(UserEntity user). I must find all entity by UserEntity which contain in this list or if it is equals to author. How I can do it?

@Entity
public class SomeEntity {
    private UserEntity author;

    private List<UserEntity> userEntityList;
}

Upvotes: 1

Views: 157

Answers (1)

Tim
Tim

Reputation: 92

Use this option

@Query("FROM SomeEntity where author = :user or :user in elements(userEntityList)")
List<Product> findAllByUserEntityListOrAuthor(@Param("user") UserEntity user);

Upvotes: 1

Related Questions