1

Hibernate is very good for code readability and database portability

However I realize that Hibernate takes a lot of memory. Here is an example

HIBERNATE VERSION

 String hql = "FROM Employee";
    Query query = session.createQuery(hql);
    List results = query.list(); // this list is limited my the size of my RAM 

JDBC VERSION

ResultSet resSet = connection.executeQuery("SELECT * FROM Employee"); 
while (resSet.next()) { 
// This resSet is not limited to my RAM
} 

So if I have a query that returns hundreds of thousands of rows, I should better handle it with JDBC, because then I can process each row sequentially, and this does not take all my RAM.

Am I correct? Or does Hibernate have any sort of "streaming List" similar to ResultSet object that does not "flood" RAM ?

john
  • 647
  • 5
  • 23
  • 53

2 Answers2

2

You can use ScrollableResults to get the results from hibernate row by row. There are examples in this answer.

Malt
  • 28,965
  • 9
  • 65
  • 105
0

Read a little bit hibernate official web:

http://hibernate.org/orm/

Answering you, there is not possible hibernate (maybe with native query https://www.mkyong.com/hibernate/hibernate-native-sql-queries-examples/) take less memory or time process than JDBC because hibernate is a abstraction of JPA and JDBC, so it was built to help developers to programming faster and easily but it will cost more resources to process it