Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

spring AOP with transactions

hi guys

I am trying to understand spring AOP transactions with hibernate in the backend.

1. In my dao-context.xml i have defined
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="${database.connection.driver}" p:url="${database.connection.url}"
p:username="${database.connection.username}" p:password="${database.connection.password}" />

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">            
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.pool_size">10</prop>
<prop key="current_session_context_class">thread</prop>                              
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction. JDBCTransactionFactory</prop>
  what does this factory do ?
<prop key="hibernate.dialect">${jdbc.hibernate.dialect}</prop>                                            
  </props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/WEB-INF/config/hibernate/hbmfiles/</value>
 <value>classpath:/WEB-INF/config/hibernate/myqueries/</value>
 </list>
 </property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />


2. and then in my dao-configs.xml i have

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*Tx" propagation="REQUIRED"/> i have method like getCustomerTx in my customerdao.
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="CustomerDaoMethods"  -- what does pointcut do ?
expression="execution(* com.customer.dao.CustomerDao.*(..))"/> --what is this?
<aop:advisor advice-ref="txAdvice" pointcut-ref="CustomerDaoMethods"/>
</aop:config>         
             
<bean id="customerDao" class="com.customer.dao.CustomerDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
      
I kind of understand the flow like who calls who. I am trying to understand what the code does, what is the functionality?
As i understand transaction is implimented on the database side. Each query is executed under a Transaction.
so i am curioous why do we have to define it like this way shown above? what benefits we have using this structure?

Any ideas/inputs  appreciated.

thanks.
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

Avatar of Jay Roy

ASKER

Do you have answer to this?
<aop:config>
<aop:pointcut id="CustomerDaoMethods"  -- what does pointcut do ?
expression="execution(* com.customer.dao.CustomerDao.*(..))"/> --what is this?
<aop:advisor advice-ref="txAdvice" pointcut-ref="CustomerDaoMethods"/>
</aop:config>

thanks
ASKER CERTIFIED SOLUTION
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial