Hello,
It seems that there is a problem with ApplicationComposer and CDI
@Transactional service.
The test class:
@EnableServices("jaxrs")
@RunWith(ApplicationComposer.class)
@Classes(cdi = true, innerClassesAsBean = true,
value = {
LoggerProducer.class,
RawService.class,
FeedsPUEntityManagerProducer.class
}
)
public class RawServiceTest extends AbstractApplicationComposerHelper {
@Resource(name = "feedsDS")
private DataSource dataSource;
@Inject
private RawService rawService;
@Test
public void extractTest() throws Exception {
Table tableFeedsFlows = new Table(dataSource,"FDS_FLOWS");
assertThatDB(tableFeedsFlows).hasNumberOfRows(0);
Long extractId = rawService.createExtractId();
assertThat(extractId).isNotNull();
tableFeedsFlows = new Table(dataSource,"FDS_FLOWS");
assertThatDB(tableFeedsFlows).hasNumberOfRows(1);
}
@Module
@PersistenceRootUrl(value = "") // must use value="" (BUG)
public Persistence generatePU() throws Exception {
return super.createPersistenceFromFile(FeedsFlows.class);
}
@Configuration
public Properties config() {
Properties properties = new Properties();
this.addDataSourceInProperties(properties, "feedsDS");
this.overridePersistenceUnitProperties("feedsPU", properties,
PersistenceUnitXmlProperties.SCHEMA_GEN_DATABASE_ACTION,
"drop-and-create");
return properties;
}
}
This seem to not work :
With EJB it's ok.
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class RawService {
@Inject
@FeedsPU
private EntityManager entityManager;
private Gson gson= new Gson();
public Long createExtractId() {
FeedsFlows extract = FeedsFlows.builder()
.startDate(new Date())
.flowType(FeedsFlowType.EXTRACT)
.rawCount(0L)
.rawBatchCount(0L)
.build();
entityManager.persist(extract);
return extract.getId();
}
But with CDI @Transactionnal :
@Dependent
@Transactional(Transactional.TxType.REQUIRES_NEW)
//@Stateless
//@TransactionManagement(TransactionManagementType.CONTAINER)
//@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class RawService {
@Inject
@FeedsPU
private EntityManager entityManager;
private Gson gson= new Gson();
public Long createExtractId() {
FeedsFlows extract = FeedsFlows.builder()
.startDate(new Date())
.flowType(FeedsFlowType.EXTRACT)
.rawCount(0L)
.rawBatchCount(0L)
.build();
entityManager.persist(extract);
return extract.getId();
}
javax.persistence.TransactionRequiredException
at
org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:159)
at
org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:189)
at
com.bnpparibas.eqd.feeds.core.srccomp.services.RawService.createExtractId(RawService.java:48)
at
com.bnpparibas.eqd.feeds.core.srccomp.services.RawServiceTest.extractTest(RawServiceTest.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at
org.apache.openejb.junit.DeployApplication$1.call(DeployApplication.java:44)
at
org.apache.openejb.junit.DeployApplication$1.call(DeployApplication.java:40)
at
org.apache.openejb.testing.ApplicationComposers.evaluate(ApplicationComposers.java:1011)
at
org.apache.openejb.junit.DeployApplication.evaluate(DeployApplication.java:40)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Do I miss something ?
Regards.
This message and any attachments (the "message") is
intended solely for the intended addressees and is confidential.
If you receive this message in error,or are not the intended recipient(s),
please delete it and any copies from your systems and immediately notify
the sender. Any unauthorized view, use that does not comply with its purpose,
dissemination or disclosure, either whole or partial, is prohibited. Since the
internet
cannot guarantee the integrity of this message which may not be reliable, BNP
PARIBAS
(and its subsidiaries) shall not be liable for the message if modified, changed
or falsified.
Do not print this message unless it is necessary,consider the environment.
----------------------------------------------------------------------------------------------------------------------------------
Ce message et toutes les pieces jointes (ci-apres le "message")
sont etablis a l'intention exclusive de ses destinataires et sont confidentiels.
Si vous recevez ce message par erreur ou s'il ne vous est pas destine,
merci de le detruire ainsi que toute copie de votre systeme et d'en avertir
immediatement l'expediteur. Toute lecture non autorisee, toute utilisation de
ce message qui n'est pas conforme a sa destination, toute diffusion ou toute
publication, totale ou partielle, est interdite. L'Internet ne permettant pas
d'assurer
l'integrite de ce message electronique susceptible d'alteration, BNP Paribas
(et ses filiales) decline(nt) toute responsabilite au titre de ce message dans
l'hypothese
ou il aurait ete modifie, deforme ou falsifie.
N'imprimez ce message que si necessaire, pensez a l'environnement.