omnifaces / omnipersistence

Utilities for JPA, JDBC and DataSources
Other
31 stars 12 forks source link

getSingleResultOrNull #7

Closed mydeadlyvenoms closed 6 years ago

mydeadlyvenoms commented 6 years ago

Hi @BalusC

What is your personal opinion about the getSingleResult method? There are many discussions about it and most of the people seem to implement kind of a helper method. Something like the following:

public static <T> T getSingleResultOrNull(TypedQuery<T> query) {
    query.setMaxResults(1);
    List<T> list = query.getResultList();
    if (list.isEmpty()) {
        return null;
    }
    return list.get(0);
}

Do you think it would make sense to add such a utility method?

BalusC commented 6 years ago

There are already several utility methods in org.omnifaces.persistence.JPA.

mydeadlyvenoms commented 6 years ago

Humpf, how could I miss this? Ready to close I guess. :-)