i want to create my query hql with my entite and i want to check if the parameter list is null or not in mariaDb
I have an entity java Student and i have a query parameter with a list.
public List<Student> findStudent(Set<Student> listStudent, Date dateReg) {
return getSession().createQuery("SELECT Student(s.studentId,s.firstname, s.lastname) FROM Student s WHERE s.studentId in (:StudentList) " +
" AND (s.registerDate =:registerDate) " +
" ORDER BY s.lastname ASC" )
.setParameter("registerDate", dateReg)
.setParameterList("StudentList", listStudent)
.list()
}
I want to reduce this query :
public List<Student> findStudent(Set<Student> listStudent, Date dateReg) {
if(listStudent != null) {
return getSession().createQuery("SELECT Student(s.studentId,s.firstname, s.lastname) FROM Student s WHERE s.studentId in (:StudentList) " +
" AND (s.registerDate =:registerDate) " +
" ORDER BY s.lastname ASC" )
.setParameter("registerDate", dateReg)
.setParameterList("StudentList", listStudent)
.list()
} else {
return getSession().createQuery("SELECT Student(s.studentId,s.firstname, s.lastname) FROM Student s WHERE s.registerDate =:registerDate " +
" ORDER BY s.lastname ASC" )
.setParameter("registerDate", dateReg)
.list()
}
}
how can i create a simple query with case when . Can you help me. My database is MariaDb 10