title: Hibernate StatelessSession, "the statement is closed" exception
body: <p>Hi I am using <code>StatelessSession</code> Interface for bulk inserts and I got an exception: "The statement is closed".</p>
  
  <p>Below are details I was using in my code, I got through google with this exception and did not found a solution.</p>
  
  <p><strong>Sample Code:</strong></p>
  
  <pre><code>    @Name("sample")
      @Scope(ScopeType.STATELESS)
      @AutoCreate
      public Sample{  
  
          @In
          private SessionFactory hibernateSessionFactory;
  
          @Begin(join=tru)
          public void migrate(){
              StatelessSession session = hibernateSessionFactory.openStatelessSession();
              Transaction tx = session.beginTransaction();
              for(DoTempCustomers tempCust:doTempCustomers){
                    TempCustomers temp=new TempCustomers();
                    BeanUtils.copyProperties(temp, tempCust);
                    session.insert(temp);
              }       
          }
  
          tx.commit();
          session.close();
       }
    }
  </code></pre>
  
  <p><strong>hibernate.cfg.xml</strong></p>
  
  <pre><code>&lt;property name="hibernate.format_sql"&gt;false&lt;/property&gt;
  &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
  &lt;property name="hibernate.session_factory_name"&gt;java:/mobeeSessionFactory&lt;/property&gt;
  &lt;property name="hibernate.connection.datasource"&gt;mobeeadminDataSource&lt;/property&gt;
  &lt;property name="hibernate.jdbc.batch_size"&gt;1&lt;/property&gt;
  &lt;property name="hibernate.cache.use_second_level_cache"&gt;false&lt;/property&gt;
  &lt;property name="hibernate.transaction.manager_lookup_class"&gt;org.hibernate.transaction.JBossTransactionManagerLookup&lt;/property&gt;
  &lt;property name="hibernate.transaction.factory_class"&gt;org.hibernate.transaction.JTATransactionFactory&lt;/property&gt;
  &lt;property name="hibernate.transaction.auto_close_session"&gt;false&lt;/property&gt;
  &lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.HashtableCacheProvider&lt;/property&gt;
  &lt;property name="hibernate.transaction.flush_before_completion"&gt;true&lt;/property&gt;
  
  &lt;!-- Here are the mappings --&gt;
  &lt;mapping package="com.manam.mobee.persist.entity"/&gt;
  &lt;mapping class="com.manam.mobee.persist.entity.TempCustomers"/&gt;
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <pre><code>Caused by: java.sql.SQLException: The statement is closed.
          at org.jboss.resource.adapter.jdbc.WrappedStatement.checkState(WrappedStatement.java:599)
          at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setString(WrappedPreparedStatement.java:313)
          at org.hibernate.type.StringType.set(StringType.java:26)
          at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
          at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:107)
          at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1997)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2243)
          ... 96 more
  12:16:54,777 INFO  [STDOUT] [Mobee]- INFO 2012-12-08 12:16:54,777 [] StringType - could not bind value 'TIMOTHY NDUNG'U MAINA' to parameter: 1; The statement is closed.
  12:16:54,777 INFO  [STDOUT] [Mobee]- WARN 2012-12-08 12:16:54,777 [] JDBCExceptionReporter - SQL Error: 0, SQLState: null
  12:16:54,777 INFO  [STDOUT] [Mobee]-ERROR 2012-12-08 12:16:54,777 [] JDBCExceptionReporter - The statement is closed.
  12:16:54,778 ERROR [STDERR] org.hibernate.exception.GenericJDBCException: could not insert: [com.manam.mobee.persist.entity.TempCustomers]
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntity
  </code></pre>
  
  <p>Can you please tell me how to solve this exception?</p>