You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Katrin Straßl <ks...@faw.jku.at> on 2015/01/13 12:48:23 UTC
Transaction management with annotations
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
--
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission.
Warning: Although the company has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.
Re: Transaction management with annotations
Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Katrin,
I am not sure if the annotation support for transations ever really
worked. At least it did not work for me when I tried it some time ago.
In the mean time I created the blueprint-maven-plugin for aries which
aims for a similar thing. It allows to do many parts of blueprint with
annotations
but works by creating the blueprint xml at compile time.
Unfortunately I did not yet do any documentation on the aries web site
but I already got an example for it:
https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi
Perhaps this could solve some of the things for you. If you want to try
it and run into problems I may be able to help you directly till there
is sufficient documenation.
Christian
--
Christian Schneider
http://www.liquid-reality.de
Open Source Architect
http://www.talend.com
Re: Transaction management with annotations
Posted by Katrin Straßl <ks...@faw.jku.at>.
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
>