persistence
persistence copied to clipboard
streamline use of 'select new' with record types
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.
Why can't we have it for non-record types? Provided there is a single public constructor
Yes, sure, it would also be allowed for non-records. Sorry for being unclear.
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
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.