gpt4 book ai didi

java - org.springframework.transaction.annotation.Transactional 与 javax.jdo.annotations.Transactional

转载 作者:行者123 更新时间:2023-11-29 07:22:42 27 4
gpt4 key购买 nike

使用 Spring 时@Transcational在服务层,我需要放置 <annotation driven>在 xml 文件上。

我想知道

  1. 可以javax.jdo.annotations.Transactional像spring一样用在服务层?无需配置 xml 文件。等等?

  2. 可以javax.jdo.annotations.Transactional在服务层上使用独立于我是否在 dao 层使用 hibernate/jpa/jdo?除了用 @Transactional 标记方法外,我还需要配置任何其他东西吗? ?

  3. javax.jdo.annotations.Transactional 之间是否存在差异/限制?和 org.springframework.transaction.annotation.Transactional ?

最佳答案

你看过 javadoc 了吗?这就是我读到的 javax.jdo.annotations.Transactional :

Annotation to indicate that a member (field or property) is transactional but not persistent. This corresponds to xml attribute persistence-modifier="transactional" of "field" and "property" elements.

这似乎与 @Transactional 没有可比性来自 Spring 的注解。

Describes transaction attributes on a method or class.

This annotation type is generally directly comparable to Spring's RuleBasedTransactionAttribute class, and in fact AnnotationTransactionAttributeSource will directly convert the data to the latter class, so that Spring's transaction support code does not have to know about annotations. If no rules are relevant to the exception, it will be treated like DefaultTransactionAttribute (rolling back on runtime exceptions).

所以,回答你的问题:

may i know can javax.jdo.annotations.Transactional be used on service layer just like spring does? do not need to configure xml files. etc?

没有。

can javax.jdo.annotations.Transactional be used on service layer independent on whether i using hibernate/jpa/jdo at the dao layer? need to configure any other things beside marking methods with @Transactional?

没有。见上文。

any different/limitation between javax.jdo.annotations.Transactional and org.springframework.transaction.annotation.Transactional?

是的。一个是苹果,另一个是橙子。

关于java - org.springframework.transaction.annotation.Transactional 与 javax.jdo.annotations.Transactional,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1896853/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com