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

streamline use of 'select new' with record types #420

Open
gavinking opened this issue May 30, 2023 · 4 comments
Open

streamline use of 'select new' with record types #420

gavinking opened this issue May 30, 2023 · 4 comments
Labels
candidate-for-4 Good candidate for JPA 4

Comments

@gavinking
Copy link
Contributor

I would like to propose that we let people write:

record BookSummary(String title, String author) {}
em.createQuery("select book.title, book.author.name from Book book", BookSummary.class).getResultList();

instead of forcing them into the extra ceremony of:

record BookSummary(String title, String author) {}
em.createQuery("select new BookSummary(book.title, book.author.name) from Book book", BookSummary.class).getResultList();

This isn't critical, of course, but it's a pretty easy simplification to the user experience.

@trajano
Copy link

trajano commented Aug 9, 2023

Why can't we have it for non-record types? Provided there is a single public constructor

@gavinking
Copy link
Contributor Author

Yes, sure, it would also be allowed for non-records. Sorry for being unclear.

@trajano
Copy link

trajano commented Aug 10, 2023

Nothing to be sorry about @gavinking I presume the purpose of this repo is to discuss things to make sure things are clear and less behaviour is unspecified and vendor dependent

@gavinking
Copy link
Contributor Author

Another thing to consider as part of this is to just do certain sorts of implicit type conversions, for example, allow:

int count = em.createSelectionQuery("select count(this) from Book", int.class).getSingleResult();

which would currently throw because count(this) is of type Long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate-for-4 Good candidate for JPA 4
Projects
None yet
Development

No branches or pull requests

2 participants