- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我调用了两个方法,第一个更新表,下一个在另一个表中插入记录。当第二个事务失败时,EJB
没有执行第一个事务的回滚。
这是我的支持 bean:
@ManagedBean
@ViewScoped
public class TransactionTestBean implements Serializable {
@EJB
private TransactionTestService service;
public String loadView() {
return "/test/transactionTest";
}
public void test() {
try {
service.updateTest();
} catch (Exception e) {
}
}
}
EJB 接口(interface):
@Local
public interface TransactionTestService {
void updateTest() throws CustomException;
}
EJB 类:
@Stateless
@TransactionManagement
public class TransactionTestServiceImpl implements TransactionTestService {
@Resource(mappedName = "java:jboss/datasources/xxxxxDS", shareable = true)
public DataSource dataSource;
private TransactionTestDAO dao;
@PostConstruct
public void init() {
dao = new TransactionTestDAOImpl();
}
@PreDestroy
public void destroy() {
dao = null;
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateTest() throws CustomException {
try (Connection connection = dataSource.getConnection()) {
dao.updateRecord(connection);
// dao.saveRecord(connection);
} catch (SQLException exception) {
throw new CustomException(exception, exception.getMessage());
}
}
}
还有我的自定义异常:
@ApplicationException(rollback = true)
public class CustomException extends Exception {
public CustomException(Throwable cause, String message) {
super(message, cause);
}
}
已编辑:
添加了 DAO 类:
public class TransactionTestDAOImpl implements TransactionTestDAO {
@Override
public void updateRecord(Connection connection) throws CustomException {
PreparedStatement preparedStatement = null;
try {
preparedStatement = connection.prepareStatement("UPDATE table_x SET field_x = ? WHERE field_y = 1");
preparedStatement.setInt(1, 1);
preparedStatement.executeUpdate();
} catch (Exception exception) {
throw new CustomException(exception, exception.getMessage());
} finally {
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException sqlException) {
}
}
}
}
}
和 DAO 接口(interface):
public interface TransactionTestDAO {
void updateRecord(Connection connection) throws CustomException;
}
最佳答案
这个案例中的关键问题是某些 JBoss 版本中数据源的错误默认设置。原始代码很好,并且在其他应用程序服务器(WebSphere App Server 和轻量级 WebSphere Liberty)中工作正常。
在 JBoss 中创建的数据源不是 JTA - 在管理控制台中 Use JTA
设置未选中,在 xml 中相关设置为 <datasource jta="false" ...
.将此设置更改为 true
解决了问题。 (JohnB,你写道定义 xa-datasource 修复了这个问题,但由于我没有看到你的原始 xml 和数据源定义,我相信在更改数据源期间你也更改了这个有缺陷的 jta="false"设置)。正如 Grzesiek 测试的那样,它也适用于非 xa 数据源。
这是一个非常糟糕的默认值,因为它会导致事务不受容器管理,并且会导致 EJB 组件中的连接出现错误的事务行为。
非常感谢Grzesiek D.谁帮我诊断了这个问题。
关于java - 事务不回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26151636/
如果我执行以下操作 session.getTransaction().rollback(); 然后可以/可以在同一个 session 对象上开始调用保存/更新/删除等吗?无法在 Hibernate S
在Sqlite3中,有没有办法在提交事务后回滚到某个点? 如果您想知道如果我不确定我为什么要提交一个语句,原因是我在 C++ 接口(interface)内使用 Sqlite,只有在我提交事务时才会保存
经过一段时间的阅读和测试不同形式的加载EntityManager实例和bean以进行一些嵌套事务,最后我没有找到一种方法,在运行时异常之后,数据进行完全回滚,必须接近阶段到什么我想要的是只有一个实体保
我们有一个应用程序,它读取 JMS 并执行一些数据库事务,所有这些都是 XA 事务的一部分。如果我们发现消息有问题,我们想要回滚数据库,但我们不希望 JMS 回滚让我们再次读取消息(如果先前已启动回滚
我有一个情况,我需要回滚数据库上的更改,而且我想保留插入的日志。 插图: Add processing log Insert some data Insert some data Insert
我定义了这样一个函数- ... DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK; DECLARE EXIT HANDLER FOR SQLWARNING
我的应用程序中有一个模型和一个类似商店的东西。模型对象使用 promise 等待存储中的数据。 但在某些情况下我需要删除模型,但因为我使用了 promise 我的模型仍处于关闭状态并且 GC 无法清理
我错误地触发了更新查询,并且 dat 字段中表中的所有记录都已更新,并且由于 auto_commit 处于打开状态,因此也无法回滚。 还有其他方法可以检索记录吗? 最佳答案 我不认为一旦提交查询/事务
我了解我可以使用 MySql 的命令 BACKUP 和 RESTORE 来备份数据库并在需要时回滚。 我的问题是,我是否能够以这种方式执行它: sql="BACKUP my_db TO DISK my
如果 MySQL 中仍有未提交/未回滚的事务,如何让我的事务等待? 目前,我在代码端进行事务处理,而不是在数据库存储过程端,如下所示: cmd.Connection.BeginTransaction(
这是以下内容的后续内容: php/mysql transaction not rolling back on failure (Codeigniter framework) 我在上面的链接中实现了建议
我只是构建了一个存储过程来测试 mysql 中的事务。 但不知何故它不起作用。 这是我的代码: USE `test`; DROP procedure IF EXISTS `testTran`; DEL
我有一个 Service Fabric 应用程序。比方说,版本 1.0.0。我将更新部署为版本 2.0.0。一切都很好。 稍后,我想回滚(或根据您的观点升级)到版本 1.0.0。 我想运行一个简单的P
我不知道这是否正确,但由于某种原因,我的存储过程在发生异常后没有回滚。所以即使我遇到异常,我的插入语句也会被提交 我忘记了什么吗? PROCEDURE SP_USUARIO_INSERT
这个问题与我的问题有关:SQL Server and TransactionScope (with MSDTC): Sporadically can't get connection 我正在使用 .n
登录到我正在使用的Oracle数据库的用户没有提交或回滚就注销了,现在我的数据库无法更改,它似乎已被锁定。 我试过了 rollback 但这没用。 有什么想法吗? 谢谢。 最佳答案 不提交或不回滚就
这只是一个 RStudio 界面问题: 当回滚控制台查看我的工作和输出时,我只能回滚到目前为止。有没有办法打开控制台并回滚我所做的一切? 有时我想检查一个很长的列表的结果,或者我忘记在脚本框而不是控制
是否可以在 Heroku 上撤消回滚? 我必须在实时环境中尝试一些东西,进行测试,然后恢复到原始状态(在回滚之前)。 Heroku 是否能够顺利做到这一点,否则会导致问题? 最佳答案 是的,您可以滚动
我想要 仅回滚: 回滚:2015_05_15_195423_alter_table_web_directories 我运行 php artisan migrate:rollback,我的 3 个迁移正
我正在使用 MQQueueSession.rollback() 来回滚工作单元。消息被移至 BACKOUT 队列,这样就可以了。 问题是如何处理回退队列中的这些消息?我读到我可以使用 runmqdlq
我是一名优秀的程序员,十分优秀!