JTA transactions issue using CDI

660 views
Skip to first unread message

Kirill Alexandrovsky

unread,
Feb 23, 2016, 8:08:20 AM2/23/16
to Sculptor Generator
Hi

I'm trying to make a cartridge that will change sculptor's DAO to Apache Deltaspike Data like it is done with Spring Data JPA. I'm using pure ejb3 helloworld example for testing the cartridge.

Apart from generating necessary repository classes and configuration classes I have followed their instructions to enable JTA transaction support (https://deltaspike.apache.org/documentation/data.html#3.CompleteAdditionalProjectConfiguration) so I think it should be configured properly. Here's my EntityManagerProducer that uses existing persistence:
public class EntityManagerProducer {

   
@Produces
   
@Dependent
   
@PersistenceContext(unitName = "UniverseEntityManagerFactory")
   
public EntityManager entityManager;
}
And repository class:
@Repository(forEntity = Planet.class)
public abstract class PlanetRepository extends AbstractEntityRepository<Planet, Long> {
   
public abstract Planet findById(Long id);

   
public abstract List<Planet> findAll();

   
public abstract Planet save(Planet entity);

   
public void delete(Planet entity) {
        remove
(entity);
   
}
}
Beans.xml contains class needed to enable JTA:
        <class>org.apache.deltaspike.jpa.impl.transaction.ContainerManagedTransactionStrategy</class>

So basically everything is in place but when running tests and trying basic operations in deployment I get errors on save and delete operations (typical stack trace):
Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.277 sec <<< FAILURE!
testSave
(org.sculptor.example.ejb.helloworld.milkyway.serviceapi.PlanetServiceTest)  Time elapsed: 0.084 sec  <<< ERROR!
javax
.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
    org
.sculptor.framework.errorhandling.UnexpectedRuntimeException[org.sculptor.framework.errorhandling.UnexpectedRuntimeException]:Failed calling Repository: [Repository=org.sculptor.example.ejb.helloworld.milkyway.domain.PlanetRepository,entity=org.sculptor.example.ejb.helloworld.milkyway.domain.Planet,method=save,exception=class org.apache.deltaspike.data.api.QueryInvocationException,message=Failed calling Repository: [Repository=org.sculptor.example.ejb.helloworld.milkyway.domain.PlanetRepository,entity=org.sculptor.example.ejb.helloworld.milkyway.domain.Planet,method=save,
    at org
.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:363)
    at org
.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:283)
    at com
.sun.proxy.$Proxy113.save(Unknown Source)
    at org
.sculptor.example.ejb.helloworld.milkyway.serviceapi.PlanetServiceTest.testSave(PlanetServiceTest.java:42)
    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:498)
    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
.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.RunAfters.evaluate(RunAfters.java:27)
    at org
.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org
.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org
.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org
.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    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:498)
    at org
.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org
.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org
.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org
.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org
.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.sculptor.framework.errorhandling.UnexpectedRuntimeException[org.sculptor.framework.errorhandling.UnexpectedRuntimeException]:Failed calling Repository: [Repository=org.sculptor.example.ejb.helloworld.milkyway.domain.PlanetRepository,entity=org.sculptor.example.ejb.helloworld.milkyway.domain.Planet,method=save,exception=class org.apache.deltaspike.data.api.QueryInvocationException,message=Failed calling Repository: [Repository=org.sculptor.example.ejb.helloworld.milkyway.domain.PlanetRepository,entity=org.sculptor.example.ejb.helloworld.milkyway.domain.Planet,method=save,
    at org
.sculptor.framework.errorhandling.ErrorHandlingInterceptor.afterThrowing(ErrorHandlingInterceptor.java:169)
    at org
.sculptor.framework.errorhandling.ErrorHandlingInterceptor.invoke(ErrorHandlingInterceptor.java:85)
    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:498)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
    at org
.sculptor.framework.context.ServiceContextStoreInterceptor.invoke(ServiceContextStoreInterceptor.java:50)
    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:498)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
    at org
.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:126)
    at org
.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:42)
    at org
.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:63)
    at org
.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:69)
    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:498)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
    at org
.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176)
    at org
.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:95)
    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:498)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
    at org
.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
    at org
.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138)
    at org
.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:239)
    at org
.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:191)
    at org
.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:246)
    at org
.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:241)
    at org
.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:83)
    at org
.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)
   
... 34 more
 
Running org.sculptor.example.ejb.helloworld.milkyway.consumer.PlanetConsumerTest
16:22:42.438 [main] INFO  o.s.e.e.h.m.c.PlanetConsumerTest - OpenEJB initialized in: 0 ms
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 sec
 
Results :
 
Tests in error:
  testSave
(org.sculptor.example.ejb.helloworld.milkyway.serviceapi.PlanetServiceTest): The bean encountered a non-application exception; nested exception is: (..)
 
Tests run: 8, Failures: 0, Errors: 1, Skipped: 0

I think this is somehow connected with transactoins mechanism, but I cannot find anything that handles this in sculptor.
Maybe this is more about testing system, but I think if read operations work fine, problem lies somewhere in transactions.

Can you suggest something that may help in resolving this issue? Maybe some sculptor classes to look into.

Thanks.

Torsten Juergeleit

unread,
Mar 9, 2016, 5:12:16 PM3/9/16
to Sculptor Generator
I've no clue about your specific issue here. But the "org.sculptor.framework.errorhandling.UnexpectedRuntimeException" is thrown by Sculptors error handling (JEE interceptor "org.sculptor.framework.errorhandling.ErrorHandlingInterceptor") while handling a RuntimeException. The original exception is logged via slf4j. So add an slf4j implementation (e.g. logback) to your test dependencies and check the output.

/Torsten

Torsten Juergeleit

unread,
Mar 9, 2016, 5:58:48 PM3/9/16
to Sculptor Generator
I think this is somehow connected with transactoins mechanism, but I cannot find anything that handles this in sculptor.

For EJB deployment Sculptor leverages the EJB containers JTA support: From the service domain objects EJB classes with the corresponding annotations and interceptors are generated.

So it's up to you to configure / annotate your generated repositories or the EJB container or the unit test (CdiTestRunner) properly to provide the expected transaction handling.

/Torsten


On Tuesday, February 23, 2016 at 2:08:20 PM UTC+1, Kirill Alexandrovsky wrote:
Reply all
Reply to author
Forward
0 new messages