我意识到将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的timeOut。我不想改变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(plage)之后放置flush()和clear(),并且仍然是相同的Exception。
final Plage plage = this.convertEnregDetailToPersist(myEnreg);
this.em.persist(plage);
this.em.flush();
this.em.clear();
Thxs。
答案 0 :(得分:4)
我注意到您使用的是org.jboss.annotation.ejb.TransactionTimeout
而不是required 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论坛找到related issue。