If my query contains one class, like:
query = session.createQuery("select u from User as u"); queryResult = query.list();
then I iterate it, where queryResult
is an object of User
class.
So how to get result from query which contains more than one class? For example:
select u, g from User as u, Group as g where u.groupId = g.groupId and g.groupId = 1
Hibernate ResultSet traversing options getResultList() method call. Hibernate also supports scrollable ResultSet cursors through its specific Query. scroll() API. The only apparent advantage of scrollable ResultSets is that we can avoid memory issues on the client-side, since data is being fetched on demand.
HQL queries are translated by Hibernate into conventional SQL queries, which in turns perform action on database.
Load multiple entities by their primary key class ); List<PersonEntity> persons = multiLoadAccess. multiLoad(1L, 2L, 3L); You just need to call the byMultipleIds(Class entityClass) method on the Hibernate Session and provide the class of the entities you want to load as a parameter.
For Hibernate Native SQL Query, we use Session. createSQLQuery(String query) to create the SQLQuery object and execute it. For example, if you want to read all the records from Employee table, we can do it through below code. When we execute above code for the data setup we have, it produces following output.
for (Object[] result : query.list()) { User user = (User) result[0]; Group group = (Group) result[1]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With