I am working on a project where I am using the Quarkus Hibernate ORM and running queries like the code below. Every time a query fails to find an entity, it throws a 500 error:
fun getByEmail(email: String): MutableList<Any?> {
return try {
em.createQuery("SELECT u FROM User u WHERE u.email = :email").setParameter("email", email).resultList
} catch (e: Throwable) {
mutableListOf()
}
}
It is quite annoying to use a try catch every time the EM is used.
My question is if there is a way to disable the NoResultError and instead return null or in this case an empty list?
I tried to disable the error in my application.properties, but it did not work.
quarkus.hibernate-orm.returning-null-on-no-result=true
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache-kotlin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-mariadb</artifactId>
</dependency>