一尘不染

事务TransactionImple ActionStatus.ABORTED已回滚

hibernate

我实现了DTO业务从TomEE到JBoss的迁移。

我有这个实体:

@NamedQueries({
@NamedQuery(name = "common.plagebusiness.plage.getAllPlages", query = "SELECT p FROM Plage p ORDER BY p.plageRgMax, p.plageCReseau") })
@Entity
@Table(name = "PLAGE")
public class Plage {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "idPlage")
    private Integer idPlage;

    @Column(name = "rgMin")
    private String plageRgMin;

使用此接口:

@Local
public interface PlagePersistenceManager {

public void importPlages(List<DetailFH55> listeEnregDetail) throws PlageBusinessException, ParseException;

}

并执行:

@Stateless(name = "common.plagebusiness.PlagePersistenceManager")
public class PlagePersistenceManagerImpl implements PlagePersistenceManager {

    private static final Logger LOGGER = Logger.getLogger(PlagePersistenceManager.class);

    @PersistenceContext(unitName = "PlageBusiness")
    private EntityManager em;

    @Override
    public void importPlages(final List<DetailFH55> listeEnregDetail) throws PlageBusinessException, ParseException {
        LOGGER.debug("Entree dans importPlages");

        if (null != listeEnregDetail) {
            LOGGER.info("Debut Delete");

            // suppression des plages
            this.deleteAllPlages();

            LOGGER.info("Fin Delete et Debut Insertion en bdd");

            for (final DetailFH55 myEnreg : listeEnregDetail) {
                // insertion des nouvelles plages
                final Plage plage = this.convertEnregDetailToPersist(myEnreg);
                this.em.persist(plage);
            }

            LOGGER.info("Fin Insertion en bdd");
        }

        LOGGER.debug("Sortie dans importPlages");

    }
}

不幸的是,em.persist无法正常工作,我有这个例外:

Caused by: javax.transaction.RollbackException: JBAS014585: Transaction 'TransactionImple < ac, BasicAction: 0:ffff0a48268b:4bc8a0e:56f01b76:18 status: ActionStatus.ABORTED >' was already rolled back

我在论坛上看到这是因为Jboss的超时。我不想更改Jboss的配置,因此我尝试通过输入,

@org.jboss.annotation.ejb.TransactionTimeout(10000000) 
public void importPlages(final List<DetailFH55> listeEnregDetail) throws PlageBusinessException, ParseException

仍然是相同的异常…此代码出了什么问题。

方法deleteAllPlages包含:

@Override
public int deleteAllPlages() throws PlageBusinessException {
    final Query query = this.em.createNativeQuery("DELETE FROM `PLAGE`");
    return query.executeUpdate();
}

我试图将persist()和clear()放在persist(plage)之后,并且仍然是相同的Exception。

final Plage plage = this.convertEnregDetailToPersist(myEnreg);
                this.em.persist(plage);
                this.em.flush();
                this.em.clear();

谢谢


阅读 390

收藏
2020-06-20

共1个答案

一尘不染

我注意到,您正在使用org.jboss.annotation.ejb.TransactionTimeout,而不是需要EJB3一个:org.jboss.ejb3.annotation.TransactionTimeout

在您的POM中,尝试用此对象替换引用您当前对象的依赖项TransactionTimeout

<dependency>
    <groupId>org.jboss.ejb3</groupId>
    <artifactId>jboss-ejb3-ext-api</artifactId>
    <version>2.2.0.Final</version>
    <scope>provided</scope>
</dependency>

然后,您可以指定值和单位:

@TransactionTimeout(value = 10, unit = TimeUnit.SECONDS).

您可以在JBoss的论坛上找到相关问题

2020-06-20