title: How to use hibernate sessions?
body: <p>The structure of my program is as follows:</p>
  
  <p>Inside my main java class:</p>
  
  <pre><code>for () // this will execute for say 5000 times ---- LINE 1
  {
      // do select on Database1 (this will select say 10000 rows) ---- LINE 2
  
      // do some computations (mainly string operations) ---- LINE 3
  
      call function1() // this will do some update on Database1 ---- LINE 4
  }
  </code></pre>
  
  <p>Now, I am trying to access Database1 using Hibernate. My question is how should I use hibernate session to access it. I am when should I start the session and when should I end it?</p>
  
  <p>If I start it before the for() loop, can I pass the same session to function1() as it is accessing the same database? Or once I do the select (LINE 1) I have to close it and open a new session in function1()?
  Optimizing the overall performance and minimizing the overall execution time is my main concern.</p>
  
  <p>I am new to Hibernate. Hence please pardon me if I am asking a very stupid doubt.</p>