81,122
社区成员




package action.merchant;
public class AddMerchantAction extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ApplicationContext ctx = SpringInitListener.getCtx();
//添加商户
MerchantInfoDAO merchantDAO = MerchantInfoDAO.getFromApplicationContext(ctx);
MerchantInfo merchant = new MerchantInfo();
merchantDAO.save(merchant);
//添加User
UserInfoDAO userDAO = UserInfoDAO.getFromApplicationContext(ctx);
UserInfo user = new UserInfo();
userDAO.save(user);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@192.166.68.42:1521:ctccpos"></property>
<property name="username" value="ctcc"></property>
<property name="password" value="oracle"></property>
<property name="maxActive" value="1000" />
<property name="maxIdle" value="50" />
<property name="minIdle" value="20" />
<property name="maxWait" value="1000" />
<property name="defaultAutoCommit" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1200000" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="1000"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">util.CustomerDialect</prop>
<prop key="hibernate.connection.charSet">GBK </prop>
<prop key="hibernate.connection.characterEncoding">GBK </prop>
<prop key="myeclipse.connection.profile">OracleThin Conn </prop>
</props>
</property>
<property name="mappingResources">
<list>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* action..*.*(..))" advice-ref="txAdvice" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" rollback-for="java.sql.BatchUpdateException"/>
<tx:method name="*" propagation="REQUIRED" rollback-for="java.sql.BatchUpdateException"/>
</tx:attributes>
</tx:advice>
</beans>
public void save(MerchantInfo transientInstance) {
log.debug("saving MerchantInfo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}