hi ove, #1 currently only std. scopes are supported by ContextControl. #2 it will work once TransactionalInterceptor gets called
regards, gerhard http://www.irian.at Your JSF/JavaEE powerhouse - JavaEE Consulting, Development and Courses in English and German Professional Support for Apache MyFaces 2014-03-07 19:12 GMT+01:00 Ove Ranheim <[email protected]>: > Hi, > > I'm not able to start the TransactionScoped in due time. I'm doing an > experiment on using ds-jpa together with JTA-and-Hibernate ( > https://github.com/jbosstm/quickstart/tree/master/jta-and-hibernate). > > The persistence.xml uses JTA and binds to a JdbcDataSource bound to JNDI. > If I use the TransactionManager directly, it all works. However, when I use > the BeanManagedUserTransactionStrategy it fails. I'd like to make use of > the @Transactional and @TransactionScope. > > Here are some code snippets. > > public static void bindNamingAndTransactionService() throws Exception { > if(txInitialized) return; > // Start JNDI server > NAMING_BEAN.start(); > > // Bind JTA implementation with default names > JNDIManager.bindJTAImplementation(); > > // Bind JTA implementation with JBoss names. Needed for JTA 1.2 > implementation. > // See https://issues.jboss.org/browse/JBTM-2054 > // resolve naming parse container for comp and bind > NAMING_BEAN.getNamingInstance().createSubcontext(new > NamingParser().parse("jboss")); > > jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerJNDIContext("java:/jboss/TransactionManager"); > jtaPropertyManager.getJTAEnvironmentBean() > > .setTransactionSynchronizationRegistryJNDIContext("java:/jboss/TransactionSynchronizationRegistry"); > JNDIManager.bindJTAImplementation(); > > JdbcDataSource dataSource = new JdbcDataSource(); > dataSource.setURL("jdbc:h2:~/partsdb;MVCC=TRUE"); > dataSource.setUser("sa"); > dataSource.setPassword(""); > > InitialContext context = new InitialContext(); > context.bind("java:/jboss/primaryDS", dataSource); > txInitialized = true; > } > > EntityManagerProducer: > > @Produces > @PartsRepository > @TransactionScoped > protected EntityManager createEntityManager() { > return entityManagerFactory.createEntityManager(); > } > > @Produces > public EntityManagerFactory entityManagerFactory() { > if (entityManagerFactory == null) { > try { > if (!txInitialized) bindNamingAndTransactionService(); > } catch (Exception e) { > throw new RuntimeException(e); > } > return Persistence.createEntityManagerFactory("primary"); > } > throw new UnsupportedOperationException(); > }; > > Arquillian Weld-Embedded-1.1 test: > > @BeforeClass > public static void beforeClazz() throws Exception { > > BeanProvider.getContextualReference(ContextControl.class).startContext(TransactionScoped.class); > } > > @Test > @Transactional > public void testMe() throws Exception { > // do something with TransactionScoped EntityManager > } > > If I move startContext to @Before method, the same error occurs. > > > Exception: > > testMe(com.parts.persistence.test.repository.PartsRepositoryTest) Time > elapsed: 0.063 sec <<< ERROR! > org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active > contexts for scope type > org.apache.deltaspike.jpa.api.transaction.TransactionScoped > at > org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:680) > at > org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:79) > at > org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:99) > at > org.jboss.weld.proxies.EntityManager$893098196$Proxy$_$$_WeldClientProxy.persist(Unknown > Source) > at > com.parts.persistence.test.repository.PartsRepositoryTest.testMe(PartsRepositoryTest.java:130) > > ideas? > > Cheers, > Ove > > >
