title: Correct way to use hibernate to populate a table with data
body: <p>I have an Equipment table that I am trying to populate with data.  The table has one auto-increment id and a manufacturer column.</p>
  
  <p>I stored all the manufacturer data in a List called manufacturerList.</p>
  
  <p>I then looped through the entire list and for each entry create a new Equipment object with that entry and store in a variable temp.  In the same loop, I try to save temp to my table using hibernate session.</p>
  
  <p>However, when I run this, I am getting this error </p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Session/EntityManager is closed</p>
  </blockquote>
  
  <p>What is correct way to implement this loop while using hibernate? </p>
  
  <pre><code>    SessionFactory factory = new Configuration()
              .configure("hibernate.cfg.xml")
              .addAnnotatedClass(Equipment.class)
              .buildSessionFactory();
  
      Session session = factory.getCurrentSession();
  
              try{
                     List&lt;String&gt; manufacturerList = new List&lt;String&gt;();
                     //populate the list here
                     //...
  
                      for (String manufacturer:manufacturerList) {
                          System.out.println(manufacturer);
                          Equipment temp = new Equipment(manufacturer);
                          session.beginTransaction();
                          session.save(temp);
                          session.getTransaction().commit();
                      }
  
              } catch (IOException e) {
                  e.printStackTrace();
              } finally {
                  factory.close();
              }
  </code></pre>
  
  <p>Thanks.</p>