Hi,
I am currently learning hibernate and its transactions - I understand the transaction as a group of operations that have to be performed together, or the so called 'rollback' occurs and in case of some error, everything backups the the previous state - we avoid many problems thanks to that...
I am writing simple application that will use Hibernate3 and i will be an electronic school register with marks from some exams. I know, that it is more like spring question, becouse I use it but still within Hibernate configuration. Is that good way for reaching above goals?
Code:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"
default-lazy-init="true">
<!--
- Root application context for the Countries application.
- Web-specific beans are defined in "countries-servlet.xml".
-->
<bean id="customerService" class="demo.service.CustomerServiceImpl">
<property name="customerDao"><ref bean="customerDao"/></property>
</bean>
<bean id="customerDao" class="demo.dao.HbCustomerDAO">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
</bean>
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames" value="*Service"/>
<property name="interceptorNames" value="txInterceptor"/>
</bean>
<bean id="daoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames" value="*Dao"/>
<property name="interceptorNames" value="txInterceptor"/>
</bean>
<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionAttributes" value="*:PROPAGATION_REQUIRED"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.p6spy.engine.spy.P6SpyDriver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3308/demo</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="hibernateProperties">
<util:properties location="hibernate.properties" />
</property>
<property name="mappingLocations">
<list>
<value>classpath:amg/demo/model/CustomerModel.hbm.xml</value>
</list>
</property>
</bean>
</beans>