I want to implement a search function with five optional variables and in every combination, so a switch/case is not a possible way. So i can't use the build in spring boot functions, because they are not dynamic (correct me if i'm wrong). I know there is the @query annotation in the crudrepository, but there is no way to write a query with optional parameters? I tried to write my own database access with jpa, without the help of spring boot CrudRepository. I read in the manual this should work:
@Autowired
@PersistenceContext
private EntityManager em;
@Transactional
public List<Persons>searchPersons(params...){}
But here is the problem, my EntityManager is always null and i have no idea why. I searched some hours and found nothing.
Maybe you guys know a way to write a dynamic SQL query in Spring Boot. Is there a way in the CrudRepository to define optional parameters for the query? Btw i use a postgreSQL database.
Many thanks for your help.