Hi again,

I still couldn't solve this. Does noone have any insights?

Regards,
Katrin

Am 13.01.2015 um 12:48 schrieb Katrin Straßl:
Hi all,

I am having troubles switching from XML-based transaction definitions to defining them with annotations.



This is the current (working) setup:

A background (Entity & DAO) OSGi-bundle with the following blueprint.xml:

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

    <bean id="sampleDAO" class="dao.bundle.SampleDAOImpl">
        <jpa:context unitname="managed-jpa" property="entityManager" />
        <tx:transaction method="*" value="Mandatory" />
    </bean>

    <service ref="sampleDAO" interface="dao.bundle.SampleDAO" />
</blueprint>

The DAO interface/implementation are straightforward with no special additions (dao.bundle.SampleDAO is the interface, dao.bundle.SampleDAOImpl the implementation).

Another bundle implements the TransferObjects and Services necessary to access the DAOs:

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

    <bean id="sampleService" class="service.bundle.SampleServiceImpl">
        <property name="dao" ref="sampleDAORef" />
        <tx:transaction method="*" value="Required" />
    </bean>
<service ref="sampleService" interface="service.bundle.SampleService" />

    <reference id="sampleDAORef" interface="dao.bundle.SampleDAO" />
</blueprint>

With this setup everything works fine, whenever a method of SampleServiceImpl is called, transactions are started as expected.



Now I wanted to migrate to annotation based transactions. To be able to test everything, I decided to leave the DAO-bundle "as is" and only change the service bundle - therefore an exeption will be thrown when the latter doesn't manage to start the transactions properly.

I followed the instructions in the following post: http://mail-archives.apache.org/mod_mbox/aries-user/201307.mbox/%3CDUB119-W223C996C7A100A34FFEBF4DF630%40phx.gbl%3E

The new service bundle blueprint.xml looks like the following:

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

    <tx:enable-annotations/>

    <bean id="sampleService" class="service.bundle.SampleServiceImpl">
        <property name="dao" ref="sampleDAORef" />
    </bean>
<service ref="sampleService" interface="service.bundle.SampleService" />

    <reference id="sampleDAORef" interface="dao.bundle.SampleDAO" />
</blueprint>

and the implementation of the SampleService looks like this:

//...
import org.apache.aries.transaction.annotations.Transaction;
import org.apache.aries.transaction.annotations.TransactionPropagationType;
//...

public class SampleServiceImpl implements SampleService {

    @Override
    @Transaction(value = TransactionPropagationType.Required)
    public List<SampleTO> getSamples() {
        //...
    }

    @Override
    @Transaction(value = TransactionPropagationType.Required)
    public SampleTO persist(SampleTO transferObject) {
        //...
sampleDAO.persist(...); // this is line 54, referenced from the stacktrace below
        //...
    }

    //... more methods that follow the scheme above
}

When I run the project now, I get the following exception:

Exception in thread "Thread-4" java.lang.IllegalStateException: tran.not.found at org.apache.aries.transaction.TransactionAttribute$1.begin(TransactionAttribute.java:37) at org.apache.aries.transaction.TxInterceptorImpl.preCall(TxInterceptorImpl.java:113) at org.apache.aries.blueprint.proxy.Collaborator.preInvoke(Collaborator.java:75) at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:52) at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)
    at com.sun.proxy.$Proxy22.getType(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:491)
at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54) at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)
    at com.sun.proxy.$Proxy22.getType(Unknown Source)
at service.bundle.SampleServiceImpl.persist(SampleServiceImpl.java:54)
    ...

The exception gets thrown when I want to call SampleServiceImpl.persist for the first time. The class that calls the method is in some foreground bundle and doesn't care about any transaction stuff - but it didn't do so with xml based transactions either.



I use Hibernate to map between entities and the database, but I don't think that this is involved in this problem. The OSGi-container is Felix 4.4.0. The following apache.aries.* bundles are deployed in my OSGi-container, whether they are relevant or not:

org.apache.aries.blueprint (1.1.0)
org.apache.aries.jndi.api, .core, .legacy.support, .rmi, .url (1.0.0 each)
org.apache.aries.jpa.api, .blueprint.aries, .container (1.0.0 each)
org.apache.aries.jpa.container.context (1.0.1)
org.apache.aries.proxy (1.0.1)
org.apache.aries.proxy.api (1.0.0)
org.apache.aries.transaction.blueprint (1.0.1) (tried with 1.0.2 aswell)
org.apache.aries.transaction.manager (1.0.1)
org.apache.aries.util (1.1.0)

If you need any other information, please let me know. I'd really like to know how I can enable annotation based transactions.

Regards,
Katrin



Reply via email to