我花了几个小时triying做回滚与EJB。 我有一个CDI控制器,我想删除某个对象。 当我尝试在EJB删除我得到一个例外,我尝试做回退,但它不工作。 每个SQL已与提交前得到的异常不回滚执行。 Obviusly这不是因为我得到另一个异常,当我尝试做回滚骨髓移植。 否则,当我试图CMT我得到休眠的异常,但我得到同样的结果BMT。
我的控制器
@Named
@Stateful
@ConversationScoped
public class PRequerimientoConjuntoCertificacionesBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1779474550283190942L;
@Inject
private Conversation conversation;
@PersistenceContext(type = PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
@Inject
private DatosSesion datosSesion;
public void eliminarDocumento() {
// TODO hay que probarlo
DocumentoGeneradoSSCC documentoEliminar;
try {
documentoEliminar = (DocumentoGeneradoSSCC) daoBase
.getEntityById(DocumentoGeneradoSSCC.class,
10);
documentoSSCCDAOBean.removeDocumentoSSCC(documentoEliminar,entityManager);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
随着EJB BMT如下:
@Stateful
@TransactionManagement(TransactionManagementType.BEAN)
public class DocumentoSSCCDAOBean implements IDocumentoSSCCDAOBeanLocal {
@Resource
private UserTransaction userTran;
@PersistenceContext(type = PersistenceContextType.TRANSACTION)
private EntityManager entityManager;
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void removeDocumentoSSCC(
DocumentoGeneradoSSCC documentoGeneradoSSCC,
EntityManager entityManager) {
// TODO hue probarlo
try {
userTran.begin();
// Eliminamos recurso asignado
entityManager
.remove(entityManager.contains(documentoGeneradoSSCC) ? documentoGeneradoSSCC
: entityManager.merge(documentoGeneradoSSCC));
userTran.commit();
} catch (Exception e) {
try {
userTran.rollback();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SystemException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
我得到这个堆栈跟踪
javax.transaction.RollbackException:ARJUNA016053:无法进行交易。
当我尝试做回滚我得到这个
java.lang.IllegalStateException:BaseTransaction.rollback - ARJUNA016074:没有交易!
我有JTA = TRUE并且standlone数据源,
<datasource jta="true" jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
我的persistence.xml是
<persistence-unit name="JusticiaGratuita"
transaction-type="JTA">
<!-- <description>Forge Persistence Unit</description> -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="${db.driver}" />
<property name="hibernate.connection.url" value="${db.url}" />
<property name="hibernate.connection.username" value="${db.user}" />
<property name="hibernate.connection.password" value="${db.pass}" />
<property name="hibernate.default_schema" value="${db.schema}" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.query.substitutions" value="true 1, false 0,'SI' 1, 'NO' 0" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.cache.use_second_level_cache"
value="true" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.show_sql" value="${db.showSql}" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.connection.provider_class"
value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="30" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="0" />
<property name="hibernate.c3p0.autocommit" value="false" />
</properties>
</persistence-unit>
:你可以在这里看到我的错误的完整堆栈跟踪http://pastebin.com/h17JD2xP
我希望得到任何帮助做回滚和解决我的问题。
问候