Jay Roy
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.Basic DataSource "
p:driverClassName="${datab ase.connec tion.drive r}" p:url="${database.connecti on.url}"
p:username="${database.con nection.us ername}" p:password="${database.con nection.pa ssword}" />
<bean id="sessionFactory" class="org.springframework .orm.hiber nate3.Loca lSessionFa ctoryBean"
p:dataSource-ref="dataSour ce">
<property name="hibernateProperties" >
<props>
<prop key="hibernate.connection. pool_size" >10</prop>
<prop key="current_session_conte xt_class"> thread</pr op>
<prop key="hibernate.transaction.fact ory_class">org.hibernate.transactio n. JDBCTransactionFactory</pr op>
what does this factory do ?
<prop key="hibernate.dialect">${ jdbc.hiber nate.diale ct}</prop>
</props>
</property>
<property name="mappingDirectoryLoca tions">
<list>
<value>classpath:/WEB-INF/ config/hib ernate/hbm files/</va lue>
<value>classpath:/WEB-INF/ config/hib ernate/myq ueries/</v alue>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework .orm.hiber nate3.Hibe rnateTrans actionMana ger"
p:sessionFactory-ref="sessionFactory" />
2. and then in my dao-configs.xml i have
<tx:advice id="txAdvice" transaction-manager="trans actionMana ger">
<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.
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.
p:driverClassName="${datab
p:username="${database.con
<bean id="sessionFactory" class="org.springframework
p:dataSource-ref="dataSour
<property name="hibernateProperties"
<props>
<prop key="hibernate.connection.
<prop key="current_session_conte
<prop key="hibernate.transaction.fact
what does this factory do ?
<prop key="hibernate.dialect">${
</props>
</property>
<property name="mappingDirectoryLoca
<list>
<value>classpath:/WEB-INF/
<value>classpath:/WEB-INF/
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework
p:sessionFactory-ref="sessionFactory" />
2. and then in my dao-configs.xml i have
<tx:advice id="txAdvice" transaction-manager="trans
<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.
ASKER
Do you have answer to this?
<aop:config>
<aop:pointcut id="CustomerDaoMethods" -- what does pointcut do ?
expression="execution(* com.customer.dao.CustomerD ao.*(..))" /> --what is this?
<aop:advisor advice-ref="txAdvice" pointcut-ref="CustomerDaoM ethods"/>
</aop:config>
thanks
<aop:config>
<aop:pointcut id="CustomerDaoMethods" -- what does pointcut do ?
expression="execution(* com.customer.dao.CustomerD
<aop:advisor advice-ref="txAdvice" pointcut-ref="CustomerDaoM
</aop:config>
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://static.springsource.org/spring/docs/2.0.8/api/org/springframework/orm/hibernate3/LocalSessionFactoryBean.html
http://static.springsource.org/spring/docs/1.2.x/api/org/springframework/orm/hibernate3/HibernateTransactionManager.html