iteye_6989 2008-06-17 00:57
浏览 252
已采纳

spring + hibernate +jta 事务不能回滚问题

[code="java"][/code] spring 配置文件

db_idcbase
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource

URL=jdbc:mysql://127.0.0.1:3306/db_idcbase?useUnicode=true&characterEncoding=gb2312;user=root;password=admin

true

3

SELECT 1

<bean id="sessionFactoryIdc"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="idcJDBC" />
    </property>
    <property name="hibernateProperties">
    <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>

</props>        

    </property>
    <property name="mappingResources">
        <list>
            <value>
                com/yiwei/hibernate/bean/TblReportHosts.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblRuleUrls.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblRuleIps.hbm.xml
            </value>
                <value>
                com/yiwei/hibernate/bean/TblRuleTcps.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblRuleUdps.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblReportUrls.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblReportKeys.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblReportTcps.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblReportUdps.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblRuleKeys.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblReportProbes.hbm.xml
            </value>
                <value>
                com/yiwei/hibernate/bean/TblReportVhosts.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblRuleConfs.hbm.xml
            </value>
            <value>
                com/yiwei/hibernate/bean/TblRuleType.hbm.xml
            </value>
            </list>
    </property></bean>


isp
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource

URL=jdbc:mysql://127.0.0.1:3306/isp?useUnicode=true&characterEncoding=gb2312;user=root;password=admin

true

3

    <property name="validatingQuery"><value>SELECT 1</value></property>
</bean>

<bean id="sessionFactoryIsp"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="ispJDBC"/>
    </property>
    <property name="hibernateProperties">
        <props>
 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  <prop key="hibernate.show_sql">true</prop>
</props>        
    </property>
    <property name="mappingResources">
        <list>
            <value>
            com/yiwei/hibernate/bean/Carrier.hbm.xml
            </value>
                    <value>
                com/yiwei/hibernate/bean/UbietyDrawer.hbm.xml
            </value>
                    <value>com/yiwei/hibernate/bean/UbietyRoom.hbm.xml</value>
                    <value>com/yiwei/hibernate/bean/User.hbm.xml</value>
                    <value>com/yiwei/hibernate/bean/Host.hbm.xml</value>
                    <value>com/yiwei/hibernate/bean/Proxyer.hbm.xml</value>
                    <value>com/yiwei/hibernate/bean/Region.hbm.xml</value>
                    <value>com/yiwei/hibernate/bean/Role.hbm.xml</value>
                    <value>
                    com/yiwei/hibernate/bean/SysPrincipal.hbm.xml
                    </value>
                    <value>
                com/yiwei/hibernate/bean/SysRolePrincipal.hbm.xml
                    </value>
            <value>
                com/yiwei/hibernate/bean/SysUserRole.hbm.xml
            </value>
                <value>com/yiwei/hibernate/bean/Log.hbm.xml</value>
                <value>com/yiwei/hibernate/bean/Vhost.hbm.xml</value>
                <value>com/yiwei/hibernate/bean/TblProxyerService.hbm.xml</value>
            </list>
    </property></bean>


<!-- jta事务 -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> 
    <property name="forceShutdown"><value>true</value></property> 
</bean>

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> 
    <property name="transactionTimeout"><value>300</value></property> 
</bean> 
<bean id="hibernateTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager">
        <ref local="atomikosTransactionManager"/>
    </property>
    <property name="userTransaction">
        <ref local="atomikosUserTransaction"/>
    </property>
</bean>

class="com.yiwei.hibernate.bean.TblRuleUrlsDAO">




class="com.yiwei.business.service.RuleUrlsServiceImp">




















PROPAGATION_REQUIRED,readOnly,-Exception


PROPAGATION_REQUIRED,readOnly,-Exception

PROPAGATION_REQUIRED,-Exception PROPAGATION_REQUIRED,,-Exception
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRED



相关代码

public class TblRuleUrlsDAO extends HibernateDaoSupport implements IRuleUrlsDAO
public void save(TblRuleUrls transientInstance) {
log.debug("saving TblRuleUrls instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (DataAccessException re) {
log.error("save failed", re);
throw re;
}
}

class LogDAO extends HibernateDaoSupport implements ILogDAO{
public void save(Log transientInstance) {
log.debug("saving Log instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (DataAccessException re) {
log.error("save failed", re);
throw re;
}
}

public class RuleUrlsServiceImp implements IRuleUrlsService {

private IRuleUrlsDAO ruleUrlsDAO;

private IRuleConfsDAO ruleConfsDAO;

private ILogDAO logDAO;
public IRuleUrlsDAO getRuleUrlsDAO() {
return ruleUrlsDAO;
}

public void setRuleUrlsDAO(IRuleUrlsDAO ruleUrlsDAO) {
this.ruleUrlsDAO = ruleUrlsDAO;
}

public void delete(TblRuleUrls persistentInstance) {
// TODO Auto-generated method stub

this.ruleUrlsDAO.delete(persistentInstance);

}

public TblRuleUrls findById(Integer id) {
// TODO Auto-generated method stub
return this.ruleUrlsDAO.findById(id);
}

public void insertUser(TblRuleUrls transientInstance,User u) {
// TODO Auto-generated method stub
try{
this.ruleUrlsDAO.save(transientInstance);
Log log = new Log();
log.setCarrierId(transientInstance.getIspID());
log.setDtime(transientInstance.getDtime());
log.setProxyerId(transientInstance.getProxyId());
String ip = transientInstance.getAssignIp().split(" ")[0];
log.setIp(ip);
log.setMessage("用户  部署了url规则 "+transientInstance.getHurl());
log.setUser(u);
log.setDtime("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
//ILogService logService = (ILogService)AppContext.getInstance().getAppContext().getBean("logService");
logDAO.save(log);
}
catch(DataAccessException e){
System.err.println("service 抛出异常");
throw e;
}

}

action

*/
public ActionForward ruleUrlsAdd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
RuleUrlsForm ruleUrlsForm = (RuleUrlsForm) form;// TODO Auto-generated
// method stub
try{
User u = (User) request.getSession().getAttribute("u");
TblRuleUrls url = new TblRuleUrls();
PropertyUtils.copyProperties(url, ruleUrlsForm);
url.setAction(ruleUrlsForm.getAct());
url.setAssignIp(request.getRemoteAddr() + " " + u.getRealName());
url.setDtime(Conversion.getDate(new Date()));
String hurl = ruleUrlsForm.getHurl();
if (ruleUrlsForm.getAct().equals("redi")||ruleUrlsForm.getAct().equals("rredi")) {
hurl = hurl + " " + ruleUrlsForm.getThurl();
}
url.setHurl(hurl);
url.setUserID(u.getId());
url.setIspID(u.getCarrierId());
url.setProxyId(u.getProxyerId());
this.getRuleUrlsService().insertUser(url,u);
}catch(DataAccessException e)
{
System.err.println("action 执行中发生异常");

}
小第 是按照 http://momoko8443.iteye.com/blog/190994

一个可以运行的例子 我的和这个列子差不多 这个可以回滚 但是我的不能 什么原因

已经三天了 我把仅有的分数都散了 再做不出来要下岗了 各位大哥帮帮忙啊

[b]问题补充:[/b]
大家帮帮忙 我 用的是mysql 5.02

  • 写回答

2条回答 默认 最新

  • lggegegmail 2008-06-17 13:20
    关注

    真的怀疑

    select table status from db_idcbase;

    你的表结构是否InnoDB的..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏