title: Hibernate opening session twice and transaction required
body: <p>First of all I want to apologize if there is something related to my question in this site. I could not find anything.
  I am developing a spring+hibernate app linked to front end written in AngularJS.
  When I invoke specific action from the front end for example:</p>
  
  <pre><code>@MessageMapping("/markVoicemailAsRead/{uniqueId}")
  public void markRead(@DestinationVariable int uniqueId) {
      Session session = sessionFactory.openSession();
      Transaction tx = null;
      try {
          tx = session.beginTransaction();
          voiceMailDao.setVoiceMailRead(uniqueId);
          tx.commit();
      } catch (HibernateException e) {
          if (tx != null)
              tx.rollback();
          e.printStackTrace();
      } finally {
          session.close();
      }
  }
  </code></pre>
  
  <p>everything is great and it works properly with my postgres db. The thing I found  weird is that in the <code>setVoiceMailRead(uniqueId)</code> I had to open another session and also I needed a transaction object. This is the implementation of the <code>setVoiceMailRead(uniqueId)</code>:</p>
  
  <pre><code>    public void setVoiceMailRead(int id) {
      Session session = sessionFactory.openSession();
      Transaction transaction = null;
      Query query = session.createQuery("update VoiceMail set read = :read"
              + " where uniqueId = :id");
      try {
          transaction = session.beginTransaction();
          query.setParameter("read", true);
          query.setParameter("id", id);
          query.executeUpdate();
          transaction.commit();
      } catch (HibernateException e) {
          if (transaction != null)
              transaction.rollback();
          e.printStackTrace();
      } finally {
          session.close();
      }
  }
  </code></pre>
  
  <p>If I remove the session ant transaction in the markRead action I get error in the console "No active transaction" so I left it this way. I believe there is something wrong with my <code>hibernate.xml</code> file and the <code>&lt;property&gt;</code> tag:</p>
  
  <p><code>&lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQL9Dialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;</code></p>
  
  <p>Thank you in advance for the responses!</p>