0

Forgive me if this is too basic a question !

I also dont expect a free lunch or dont want to come across as someone who wants others to do my homework

I did google around and read details on SO also but I am really confused on this

Here is what I have working I just need to simply do a search and return results from the database

We are using weblogic and hence a managed environment which gives me connections

We have configured the session factory details like this :

<hibernate-configuration>
  <session-factory>
    <property name="connection.datasource">MYDS</property>
    <property name="show_sql">true</property>
    <property name="default_schema">CLIENT1SCHEMA</property>
  </session-factory>
</hibernate-configuration>

In my spring application context - have defined a sessionFactory and TransactionManager and then inject the session factory in my DAO

<bean id="sessionFactoryX" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  <property name="configLocation" value="classpath:abc.hibernate.cfg.xml" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryX" />
</bean>

<bean id="myCustomDao" class="com.xyz.MyCustomDao" lazy-init="true">
  <property name="criteriaConverter" ref="criteriaConverter" />
  <property name="sessionFactory" ref="sessionFactoryX" />
</bean>

Now in my dao - I simply want to do a search - so here is what I have implemented :

public List<T> findAll(final HashMap param) {
    List<T> 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;   

}

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 : Transaction Management using Hibernate with weblogic

Now here is my basic question : I have no Transaction management code explicitly written : neither in my service layer via AOP nor @Transactional

It seems to work simply with the injection of :

org.springframework.orm.hibernate4.HibernateTransactionManager

So is this valid transaction management ?

I am trying to implement Multitenancy -as per earlier thread - but thats not my question here

Thanks

Community
  • 1
  • 1
satish marathe
  • 1,073
  • 5
  • 18
  • 37

1 Answers1

0

This configuration should not be enough to have proper tx management.

To test it, i advise you to create a write operation that will write changing data each call (like current date), in your dao.

Put two calls to this method in a service method, debug, pause before first dao method invocation, and do a select using an external client to see what will be modified.

Let the spring app call the dao once, do another time the select. If the value has changed now, wihtout going out of the service method, you don't have proper tx management (and most certainly, you have a jdbc connection in auto-commit mode).

Thierry
  • 5,270
  • 33
  • 39
  • thanks - I am now confused - what is the point of defining the HibernateTransactionManager ? - so does this mean that in my service layer I will have to write transaction management ( either declarative or with Transactional annotations ? ) – satish marathe Dec 18 '14 at 14:36