title: Transaction management when using Hibernate and Spring
body: <p>Forgive me if this is too basic a question ! </p>
  
  <p>I also dont expect a free lunch or dont want to come across as someone who wants others to do my homework </p>
  
  <p>I did google around and read details on SO also but I am really confused on this </p>
  
  <p>Here is what I have working 
  I just need to simply do a search and return results from the database </p>
  
  <p>We are using weblogic and hence a managed environment which gives me connections </p>
  
  <p>We have configured the session factory details like this :</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;property name="connection.datasource"&gt;MYDS&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
      &lt;property name="default_schema"&gt;CLIENT1SCHEMA&lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>In my spring application context - have defined a sessionFactory and TransactionManager and then inject the session factory in my DAO</p>
  
  <pre><code>&lt;bean id="sessionFactoryX" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
    &lt;property name="configLocation" value="classpath:abc.hibernate.cfg.xml" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
  &lt;property name="sessionFactory" ref="sessionFactoryX" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="myCustomDao" class="com.xyz.MyCustomDao" lazy-init="true"&gt;
    &lt;property name="criteriaConverter" ref="criteriaConverter" /&gt;
    &lt;property name="sessionFactory" ref="sessionFactoryX" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now in my dao - I simply want to do a search - so here is what I have implemented :</p>
  
  <pre><code>public List&lt;T&gt; findAll(final HashMap param) {
      List&lt;T&gt; listData = null;
      Criteria subSelectCriteria =null;
  try {
      Session session=getSessionFactory().getCurrentSession();
      subSelectCriteria =session.createCriteria(getType());
      } catch (HibernateException e) {
          e.printStackTrace();
      }
  boolean isDistinctQuery=false;
      subSelectCriteria.setFirstResult(0);
      subSelectCriteria.setMaxResults(100);
      List inObjList = subSelectCriteria.list();
      if(!inObjList.isEmpty()){
          listData = inObjList;
      } 
  return listData;   
  </code></pre>
  
  <p>}</p>
  
  <p>This all works fine and this above configuration was reached after facing a lot of issues related to Transaction management - which I had posted here :
  <a href="https://stackoverflow.com/questions/27344393/transaction-management-using-hibernate-with-weblogic">Transaction Management using Hibernate with weblogic</a></p>
  
  <p>Now here is my basic question :
  I have no Transaction management code explicitly written :
  neither in my service layer via AOP nor @Transactional </p>
  
  <p>It seems to work simply with the injection of :</p>
  
  <blockquote>
    <p>org.springframework.orm.hibernate4.HibernateTransactionManager</p>
  </blockquote>
  
  <p>So is this valid transaction management ?</p>
  
  <p>I am trying to implement Multitenancy -as per earlier thread - but thats not my question here </p>
  
  <p>Thanks</p>