I have a large project sitting on top of a large database with multiple tables. Data gets inserted, updated, queried (including joins) and deleted. Up to and including Hibernate 6, I've been using createNativeQuery for some of these operations, particularly when the returned results are complex (e.g. "select a.something,b.somethingelse from table1 a left join table 2 b on (b.thisfield=a.thatfield) where (a.anotherfield in (select anotherfield from table3 where somedate>=:adate))")
Up until now, I could do that just by calling .createNativeQuery(sqlstring), set the parameters, execute and then read the results using ResultSet and .getInt, .getString etc.
Now, apparently, I have to supply a class - yet I'm not actually wanting to create a new table, this is a set of fields from different tables! How on earth do I do what I'm trying to do?
This is a simple example - the real queries are far more complex, and there are lots of them... All the examples I find online are either for ridiculously simple single table cases (e.g. .createNativeQuery("select * from customers",Customer.class)) or date back years to when just .createNativeQuery(sqlstring) was still allowed.
(Additionally, I'd like to know what class I should be using when the query doesn't actually return anything anyway, e.g. a delete from... or update... set... where...)
Thanks for any pointers!
createNativeMutationQueryin the same documentation from @M.Deinum above.