title: Hibernate Template Session query
body: <p>We are using Spring HibernateTemplate class for hibernate operation. I need to execute a query with in clause and setting the options for in using an arrayList. For that i need a org.hibernate.Query object.</p>
  
  <pre><code>String queryStr = "from CertMetadataCfg where metadataId in (:metadataIds)";
  Query query=hibernateTemplate.getSessionFactory().openSession().createQuery(queryStr)
  query.setParameterList("metadataIds", metadataSet);
  </code></pre>
  
  <p>but for retrieving Query object we have to open a new session. Why do we need to open a session. and when should we close this session .</p>