Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queryable.getSingleResult alternatives #1934

Open
haraleib opened this issue Sep 11, 2024 · 0 comments
Open

Queryable.getSingleResult alternatives #1934

haraleib opened this issue Sep 11, 2024 · 0 comments
Labels
component: core kind: enhancement worth: medium Implementing this has a medium worth

Comments

@haraleib
Copy link

haraleib commented Sep 11, 2024

It would be nice if com.blazebit.persistence.Queryable would offer alternative Methods for getSingleResult. In fact a Method which swallows NoResultsException and NonUniqueResultException. A proper Naming would be findSingleResult. As this two Exceptions are unchecked Exceptions, very often it is not very safe to use getSingleResult, unless you really know your data.

Maybe instead of findSingleResult a Method which returns an Optional could be a good solution too.

criteriaBuilderFactory.create(em, CatView.java)
            .where("id").eq(catId)
            .findSingleResult();
criteriaBuilderFactory.create(em, CatView.java)
            .where("id").eq(catId)
            .getSingleResultOptional();
@beikov beikov added kind: enhancement component: core worth: medium Implementing this has a medium worth labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core kind: enhancement worth: medium Implementing this has a medium worth
Projects
None yet
Development

No branches or pull requests

2 participants