问题标签 [spring-transactions]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
4 回答
13831 浏览

java - 何时在 Spring 和 Hibernate 中使用事务?

升级我的项目我在这里考虑交易。
好吧,问题是我不太确定什么时候应该在 Spring 中将事务用于我的 Hibernate 查询。
并不是说我完全不了解事务是什么,我想我知道,但是
我是否需要将事务用于仅设置属性的get*类型查询?read-only

这对get*查询有效吗?
因为,就我而言,应该像 for CREATEUPDATEDELETE这样的查询那样使用事务。
我在这里错过了什么吗?

0 投票
1 回答
263 浏览

java - How to make service use particular txAdvice in Spring?

I'm trying to upgrade my project and so I've come to transactions. This is how I did it up to now.

I changed the transaction attributes like this bellow, but I'm not quite sure how could I link the service with exactly this txAdvice. Cause I generally have different transaction attributes for different services so there I guess should be more than one txAdvice. Is there a way how to say the @Transactional to use this particular txAdvice?

0 投票
1 回答
986 浏览

namespaces - STS + gwt + spring-config 文件 + tx:annotation 命名空间

我已经坚持了一段时间。我一直在开发一个 gwt + spring 后端 java 项目。我的项目是一个 GWT 项目和另一个用于 Spring 服务的 java 项目等的结构。每个项目都包含它们各自的 spring-config 文件。如果我要使用,则尝试加载弹簧配置 tx:annotation-driven

我不断得到以下信息。 org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'.

应该提到我正在使用 Eclipse 的谷歌插件在 sts 内的 gwt 容器中进行部署。

我的 spring-servlet 命名空间是这样开始的

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="h ttp://www.w3.org/2001/XMLSchema-instance" xmlns:aop="h ttp://www.springframework.org/schema/aop" xmlns:context="h ttp://www.springframework.org/schema/context" xmlns:p="h ttp://www.springframework.org/schema/p" xmlns:util="h ttp://www.springframework.org/schema/util" xmlns:tx="h ttp://www.springframework.org/schema/tx" xsi:schemaLocation="h ttp://www.springframework.org/schema/aop h ttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd h ttp://www.springframework.org/schema/beans h ttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd h ttp://www.springframework.org/schema/util h ttp://www.springframework.org/schema/util/spring-util-3.0.xsd h ttp://www.springframework.org/schema/tx h ttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd h ttp://www.springframework.org/schema/context h ttp://www.springframework.org/schema/context/spring-context-3.0.xsd"> <tx:annotation-driven transaction-manager="transactionManager"/>

我已经阅读了很多帖子来理解它,但未能解决这个问题。a) 尝试使用 : 将模式导入 xml 目录 jar:file:path/to/spring-framework-3.0.5.RELEASE/dist/org.springframework.transaction-3.0.5.RELEASE.jar!/org/springframework/transaction/config/spring-tx-3.0.xsd ,其中键为http://www.springframework.org/schema/context/spring-context-3.0.xsd,类型为模式位置。

感谢任何帮助或指示!

0 投票
1 回答
367 浏览

java - 事务管理器不承担事务

我遇到了一个问题,我真的不知道如何抓住猫尾巴(如果你把我开玩笑:o))

我有一个 webapp 在战争中,部署在 tomcat 中。战争包含 4 个罐子。4个jar有4个applicationContext,4个entityManager,4个TransactionManager。

像这样声明(更改数字 1..):

上下文是这样加载的:

我的问题是,我发现当我使用 3 的 BO 时,事务以 2 的数据源打开。

此外,如果我坚持下去,我会收到以下信息:

AbstractSaveEventListener - 由于没有正在进行的交易而延迟身份插入

但是,如果我单独启动 jar 1(例如),一切正常。

非常感谢您的启发。

0 投票
2 回答
967 浏览

java - 使用@Transactional 的类层次结构问题

项目设置:Spring 3.0.5 / JPA 2 / Hibernate / @Transactional

我们使用几个不同的数据源(因此也使用不同的事务管理器),但有共同的服务基类,因为很多功能都被重用了。

所以我们认为我们可以通过使用自定义注释来解决这个问题。我们在一个抽象基类中定义所有方法,并为每个事务管理器创建一个空的实现类。

现在的问题是:

AbstractFallbackTransactionAttributeSource中,这是正在执行的查找:

首先检查方法,然后检查声明该方法的类(及其祖先)。但是在我们的上下文中,自定义注解位于一个子类中,不能通过向上找到。

那么我们该如何解决这个问题呢?

【我在Spring社区论坛也问过这个问题】

0 投票
9 回答
131922 浏览

spring - 匹配的通配符是严格的,但找不到元素 'tx:annotation-driven' 的声明

我正在尝试配置 JSF+Spring+hibernate 并且我想运行一个测试但是当我在我的 application-context.xml 文件上使用这个“tx:annotation-driven”时,我收到了这个错误:

匹配的通配符是严格的,但找不到元素 'tx:annotation-driven' 的声明

这是我的 application-context.xml:

这是我的 CourseServiceImplTest。我还没有实现测试:

这是 CourseServiceImpl:

0 投票
1 回答
1263 浏览

datasource - Spring TransactionManager 与 BoneCP 连接池的集成

我正在使用 BoneCP 连接池机制,并且我想使用 Spring 框架的支持来管理我的事务。我找到了一个关于Spring Transaction Management的示例,并尝试应用此示例。我从我的连接池中获得了一个 DataSource 实例,并将这个数据源提供给创建的 DataSourceTransactionManager,如下所示。

但是当我测试它时,我看到事务管理器在提交操作之前已经将数据写入存储。

是否与创建事务管理器之前创建新数据源有关?或者你有什么想法吗?

0 投票
4 回答
87879 浏览

java - @Transactional 方法调用另一个没有@Transactional 注释的方法?

我在 Service 类中看到了一个标记为 的方法@Transactional,但它也调用了同一个类中未标记为 的一些其他方法@Transactional

这是否意味着对单独方法的调用导致应用程序打开与数据库的单独连接或暂停父事务等?

没有任何注释的方法被另一个带有@Transactional注释的方法调用的默认行为是什么?

0 投票
1 回答
523 浏览

spring - spring-managed-transaction 可以在多个 request-response-s 中存活吗?

我目前正在使用 jsf 2、jpa 2 和 spring 3 进行开发。

我想我很理解@Transactional 的使用和它的传播,但仍然只适用于一个线程,在我的情况下是我的webapp 的一个请求响应

基本上我需要的是:

  1. 远程业务服务的客户端是发起和结束事务的客户端
  2. 如果发生任何异常,spring 将进行异常翻译

这是一个希望可以描述意图的示例:

  1. 客户端(假设它是移动设备,不一定是 web 应用程序)要求服务器创建新事务
  2. 服务器返回一个事务 id
  3. 客户端调用 serviceA,传递 transactionId 以使用
  4. serviceA 使用事务运行(基于传递的 transactionId)完成,但事务未提交
  5. 客户端继续调用 serviceB,传递相同的 transactionId 以使用
  6. serviceB 使用 serviceA 发起的上一个事务运行
  7. 如果 serviceB 运行正常,则客户端可以根据 transactionId 请求服务器提交
  8. 如果 serviceB 运行异常,spring 可以进行 sql 异常翻译

这可能吗 ?

谢谢 !

0 投票
1 回答
557 浏览

spring - 我可以在不使用 spring-managed-transaction 的情况下使用 spring 异常翻译吗?

我正在使用 JPA 2 和 Spring 3 进行开发。

我正在为我的 Dao 类使用@Repository,希望我可以利用 Spring 异常翻译。

但问题是,我没有使用 spring 托管事务(没有 @Transactional,在我的 spring 配置文件中没有定义 transactionManager),而是为我的 JPA 应用程序处理自定义事务。

是否仍有可能以某种方式利用我的自定义事务管理器的翻译?这个自定义事务管理器的实现仍然使用 JPA 中的 EntityManagerFactory 和 EntityManager。

请分享你的想法。

谢谢 !