title: Hibernate SessionFactory getCurrentSession is not valid without active transaction
body: <p>I am facing one problem in Hibernate. Here is the code.</p>
  
  <pre><code>    Configuration cfg = new Configuration().configure();
      SessionFactory factory = cfg.buildSessionFactory();
      Session session = factory.openSession();
  
      Transaction trans = session.beginTransaction();
      trans.begin();
      Session session2 = factory.getCurrentSession();
      System.out.println(session2.isConnected());
  
      trans.commit();
  </code></pre>
  
  <p>And in my cfg file </p>
  
  <pre><code>  &lt;session-factory&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:sqlserver://localhost:1433&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;username&lt;/property&gt;
      &lt;property name="connection.password"&gt;password&lt;/property&gt;
      &lt;property name="connection.pool_size"&gt;5&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="hbm2ddl.auto"&gt;false&lt;/property&gt;
      &lt;mapping resource="Test.hbm.xml"/&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p>when i run the application with above code it is giving me an Exception saying "org.hibernate.HibernateException: isConnected is not valid without active transaction"</p>
  
  <p>I don't know what behavior its performing internally. Any idea's please. </p>