4

我有两个对象 Antrag(应用程序)和 Anlage(设施)。可以申请多个设施。应用程序直接保存在 DAO 中。这些设施通过级联进行持久化。

@Entity
@Table(name = "EEG_ANTRAG")
public class Antrag implements Serializable {
  private static final long serialVersionUID = -2440344011443487714L;

  @Id
  @Column(name = "ANT_ID", nullable = false)
  @SequenceGenerator(name = "sequenceGeneratorAntrag", sequenceName = "EEG_ANTRAG_SEQ", allocationSize = 1)
  @GeneratedValue(generator = "sequenceGeneratorAntrag")
  @Getter @Setter private Long id;

  @OneToMany(mappedBy = "antrag", cascade = { CascadeType.ALL }, orphanRemoval = true)
  @OrderBy("id ASC")
  @Getter private List<Anlage> anlageList = new ArrayList<Anlage>();

  public Anlage addAnlage(Anlage anlage) 
    anlageList.add(anlage);
    anlage.setApplication(this);
    return anlage;
  }

  /* some more simple attributes; just Strings, boolean, .. */
}

@Entity
@Table(name = "EEG_ANLAGE")
public class Anlage implements Serializable {    
  private static final long serialVersionUID = -3940344011443487741L;

  @Id
  @Column(name = "ANL_ID")
  @SequenceGenerator(name = "sequenceGeneratorAnlage", sequenceName = "EEG_ANLAGE_SEQ", allocationSize = 1)
  @GeneratedValue(generator = "sequenceGeneratorAnlage")    
  @Getter @Setter private Long id;

  @ManyToOne
  @JoinColumn(name = "ANL_ANT_ID")
  @Getter @Setter private Antrag antrag;

 /* some more simple attributes; just Strings, boolean, .. */
}

@Stateless
public class AntragDaoBean implements AntragDaoLocal {
  @PersistenceContext(unitName = "ejb-model")
  private EntityManager em;

  @Override
  public void persistAntrag(Antrag antrag) {
    em.persist(antrag);
  }
}

当插入工具发生错误时,例如实体中的某些列名拼写错误,则会引发异常。堆栈跟踪表明已执行回滚。问题是,应用程序仍然存在。应用程序的插入不应该也被回滚吗?我们正在使用 EclipseLink 2.4.1。EclipseLink 调试输出表明所有插入都在一个事务中执行。数据库是Oracle 11g。我对交易行为的期望是错误的吗?如何获得我想要的行为?

/* shortened exemplary stacktrace for rollback */
EvaluationException:
  javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
EJBTransactionRolledbackException:
  org.jboss.as.ejb3.tx.CMTTxInterceptor.handleEndTransactionException(CMTTxInterceptor.java:115)
RollbackException:
  com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1177)
DatabaseException:
  org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
SQLSyntaxErrorException:
  oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
4

1 回答 1

8

你的期望是正确的:一切都应该在一个事务中完成,并且插入也Antrag应该回滚。

我认为你的持久性单元根本不是 JTA:在persistence.xml文件中测试你有类似的东西:

<persistence-unit name="ejb-model" transaction-type="JTA">
<jta-data-source>java:/someNameDB</jta-data-source>
于 2013-10-29T11:13:07.727 回答