Reputation: 603
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
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