I am using Tomcat 5.5, Oracle Express and Spring 2.6. Now I have problems in transaction. I did all setup, but transaction doesn't work.
Code:<bean id="MtsDao" class="dao.MtsDaoImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="mtsTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="MtsServiceTarget" class="service.MtsServiceImpl"> <property name="mtsDao" ref="MtsDao" /> </bean> <bean id="MtsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="mtsTxManager"/> <property name="target" ref="MtsServiceTarget"/> <property name="transactionAttributes"> <props> <prop key="increasePrice">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop> </props> </property> </bean> <!-- ///////////////// Hibernate /////////// --> <!-- DataSource Property --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@localhost:1521/XE</value> </property> <property name="username" value="t" /> <property name="password" value="t" /> </bean> <!-- Database Property --> <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="hibernate.dialect"> org.hibernate.dialect.OracleDialect </prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.c3p0.minPoolSize">5</prop> <prop key="hibernate.c3p0.maxPoolSize">20</prop> <prop key="hibernate.c3p0.timeout">600</prop> <prop key="hibernate.c3p0.max_statement">50</prop> <prop key="hibernate.c3p0.testConnectionOnCheckout"> false </prop> </props> </property> </bean> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource" /> </property> <property name="hibernateProperties"> <ref bean="hibernateProperties" /> </property> <property name="mappingResources"> <list> <value>project.hbm.xml</value> </list> </property> </bean>
In the Dao,
In the service,Code:public void addPeople(String name){ People p = new People(); p.setTitle(name); Ticket t = new Ticket(); List ticketList = new ArrayList(); ticketList.add(t); p.setTicketList(ticketList); this.getHibernateTemplate().saveOrUpdate(p); }
test transaction, but failed, the data is not roll-back.Code:public void increasePrice() throws Exception { //System.out.println("---invoke dao, get result="+mtsDao.getPeople()); mtsDao.addPeople("manager4"); System.out.println("---throw excetpion, test transaction---"); if(true) throw new Exception("test transaction"); mtsDao.addPeople("staff4"); }
Any hints ? Did I miss anything ?
Thanks.


Reply With Quote
