OpenJPA, Aries Transaction BluePrint, Can only perform operation while a transaction is active

316 views
Skip to first unread message

Alex Soto

unread,
May 16, 2018, 9:44:14 AM5/16/18
to OPS4J
Hello,

I am trying to get transaction support for my JPA project.  I get this error:

Caused by: org.apache.openjpa.persistence.TransactionRequiredException: Can only perform operation while a transaction is active.
    at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(BrokerImpl.java:4723) ~[?:?]
    at org.apache.openjpa.kernel.DelegatingBroker.assertActiveTransaction(DelegatingBroker.java:1385) ~[?:?]
    at org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663) ~[?:?]
    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.aries.jpa.support.osgi.impl.EmProxy.invoke(EmProxy.java:43) ~[?:?]
    at com.sun.proxy.$Proxy94.flush(Unknown Source) ~[?:?]
    at Proxy1e882fa8_f541_465e_9200_58ace778aff6.flush(Unknown Source) ~[?:?]

My Blueprint XML is:

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
    xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

    <jpa:enable />
    <tx:enable-annotations />

    <bean id="userService" class="org.data.service.impl.UserServiceImpl"/>
    <service ref="userService" interface="org.data.service.UserService" /> 
</blueprint>


My Service:

import static javax.transaction.Transactional.TxType.REQUIRED;
import static javax.transaction.Transactional.TxType.SUPPORTS;
import javax.transaction.Transactional;
...
    @Override
    @Transactional(REQUIRED)
    public void updateUser(User user) {
        em.persist(user);
        em.flush();
    }


Log file shows the interceptor:

48 - org.apache.aries.transaction.blueprint - 1.1.1 | Component userService.addUser is txType Supports.
48 - org.apache.aries.transaction.blueprint - 1.1.1 | PreCall for bean userService, method addUser with tx strategy SUPPORTS.
43 - org.apache.aries.jpa.blueprint - 2.6.1 | PreCall for bean userService, method addUser
45 - org.apache.aries.jpa.support - 2.6.1 | Creating EntityManager for persistence unit responderPersistenUnit, coordination txInterceptor.org.data.service.UserService.addUser
43 - org.apache.aries.jpa.blueprint - 2.6.1 | PostCallWithException for bean userService, method addUser
org.apache.openjpa.persistence.TransactionRequiredException: Can only perform operation while a transaction is active.
    at org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(BrokerImpl.java:4723) ~[?:?]
    at org.apache.openjpa.kernel.DelegatingBroker.assertActiveTransaction(DelegatingBroker.java:1385) ~[?:?]
    at org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663) ~[?:?]
    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.aries.jpa.support.osgi.impl.EmProxy.invoke(EmProxy.java:43) ~[?:?]
    at com.sun.proxy.$Proxy94.flush(Unknown Source) ~[?:?]
    at Proxy1e882fa8_f541_465e_9200_58ace778aff6.flush(Unknown Source) ~[?:?]


Any idea how to make it work or troubleshoot this?
Versions:

org.apache.aries.transaction.blueprint: 1.1.1
org.apache.aries.jpa.blueprint:              2.6.1
OpenJPA:                                              2.4.2


Thanks in advance

Christian Schneider

unread,
May 16, 2018, 7:21:00 PM5/16/18
to op...@googlegroups.com
Are you maybe calling this method from the same class? In this case the interceptor that does the transaction management is not invoked.

Christian

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

Reply all
Reply to author
Forward
0 new messages