我有两个对象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)