Transaction does not work
lfelipeas May 27, 2011 4:20 PMI have a method where I create a new transaction to persist some objects. But when it goes to commit it simply does nothing. Passes by.
Here is the code:
@Transactional
public void insertWithTransaction(PmnGrupoAssistenciaTecnica grupoAstec, PmnProfissionalUtilizado profUtil,
PmnGrupoProfissional grupoPro) {
Transaction tx = ((Session) (getEntityManager().getDelegate())).getTransaction();
try {
tx.begin();
getEntityManager().persist(grupoAstec);
getEntityManager().persist(profUtil);
getEntityManager().persist(grupoPro);
tx.commit();
}
catch(Throwable e) {
tx.rollback();
e.printStackTrace();
}
}
Here goes my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <!-- Persistence deployment descriptor for dev profile --> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="BL" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/BLDatasource</jta-data-source> <!-- The <jar-file> element is necessary if you put the persistence.xml in the WAR and the classes in the JAR --> <!-- <jar-file>../../vehicles.jar</jar-file> --> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/BLEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
And my components.xml:
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
xmlns:core="http://jboss.com/products/seam/core"
xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:drools="http://jboss.com/products/seam/drools"
xmlns:bpm="http://jboss.com/products/seam/bpm"
xmlns:security="http://jboss.com/products/seam/security"
xmlns:mail="http://jboss.com/products/seam/mail"
xmlns:web="http://jboss.com/products/seam/web"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:transaction="http://jboss.com/products/seam/transaction"
xsi:schemaLocation=
"http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd
http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd">
<component name="DATE_FORMATTER" class="org.domain.bl.converter.DateFormatter" auto-create="true" scope="application" >
<property name="timeZone">#{timeZone}</property>
</component>
<core:init debug="true" jndi-pattern="@jndiPattern@"/>
<core:manager concurrent-request-timeout="500"
conversation-timeout="120000"
conversation-id-parameter="cid"
parent-conversation-id-parameter="pid"
uri-encoding="ISO-8859-1"/>
<!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
<web:hot-deploy-filter url-pattern="*.seam"/>
<web:character-encoding-filter override-client="true" encoding="ISO-8859-1"></web:character-encoding-filter>
<persistence:managed-persistence-context name="entityManager" auto-create="true"
persistence-unit-jndi-name="java:/BLEntityManagerFactory" />
<drools:rule-base name="securityRules">
<drools:rule-files>
<value>/security.drl</value>
</drools:rule-files>
</drools:rule-base>
<security:rule-based-permission-resolver security-rules="#{securityRules}"/>
<security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
<event type="org.jboss.seam.security.notLoggedIn">
<action execute="#{redirect.captureCurrentView}"/>
</event>
<event type="org.jboss.seam.security.loginSuccessful">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
<event type="org.jboss.seam.exceptionHandled">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
<mail:mail-session host="localhost" port="25"/>
<!-- For use with jBPM pageflow or process management -->
<!--
<bpm:jbpm>
<bpm:process-definitions></bpm:process-definitions>
<bpm:pageflow-definitions></bpm:pageflow-definitions>
</bpm:jbpm>
-->
</components>
Can somebody help me?
Thanks!