I have some Entity with unique field name
:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "products")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, unique = true)
private String name;
}
I need to know what exceptions may this function throw:
public List<Product> findAllByName(List<String> names);
I know from documentation, that findAllBy*
methods will throw IllegalArgumentException
if pass null (or some list element is null).
But what will this method return if:
names
size.And I'm really interested in the 2 case. If the exception is not thrown, should I throw it by my own?
First of all I suggest you to read more attentively the documentation about CrudRepository method. The answers of your questions is clearly wrote on it. For example, for findAllById(... ids) method, doc says :
If some or all ids are not found, no entities are returned for these IDs.
So, if no ids are found, no entities will be returned and you will got an empty list. Otherwise, if some ids are found, matching entities will be returned and you will got list containing only matching entities. Your method should not have to always return a list whose size is equal to your names list size