Say, I have the following entity class:
Person.java
@Entity
public class Person {
@Id
private String name;
private String[] cars;
// Constructor, getters and setters
}
And the repository:
PersonRepository.java
public interface PersonRepository extends CrudRepository<Person, String> {
// this is unclear!
List<Person> getAllByCars...(String car)
}
Is there a method that returns all persons, whose car array contains one given car (the String parameter above)?
For me, it seems that all supported JPA keywords can only deal with single elements, but not with arrays.
Thanks for help!
Ideally, You should declare cars as a separate Entity like this
If not you should change Array to List at the least. change
to
Then You have to write a Query like this
I'm guessing at how you are currently storing the cars information and suggesting a possible solution: