Spring transactions with aspectj on Virgo [message #660727] |
Mon, 21 March 2011 12:23 |
Eclipse User |
|
|
|
Originally posted by: james.ractive.ch
Hello everyone
Our OSGi based application builds on Virgo 2.1.0, Spring 3.0.5,
Eclipselink 2.2 and JPA 2. We have separate bundles for the domain
classes, the JPA services and the web application. We followed the setup
of the greenpages application - more or less. And reading entities from
the embedded H2 database works great.
When trying to insert a new entry into the DB, we figured out that no
transactions have been created in the JPA bundle. Calls to em.persist()
had simply no effect. There was no exception or error in the log, but
the object simply has not been created. Question: Shouldn't there be
some kind of warning that no transaction is present and that persist()
will not do anything?
After a lot of debugging, we changed the transaction mode from "aspectj"
to "proxy" in the spring configuration:
<tx:annotation-driven mode="proxy" />
Now transactions are created and new objects can be persisted.
What do we have to configure so that virgo is able to perform the load
time weaving with aspectj instead of using proxies? I read that virgo
has built-in load time waving capabilities [1], but I do not find any
useful documentation or examples, how to configure the spring
application to be able to use it.
I also tried to extend the Greepages application to create directory
listing and I ran into the exact same issue. The creation of a new
listing is silently ignored, because no transaction is created.
Let me know if you need more information about the configuration of our
bundles.
Thanks so far,
James
[1]
http://martinlippert.blogspot.com/2009/04/load-time-weaving- for-spring-dm.html?showComment=1240753860000#c83177281249561 89651
|
|
|
|
Re: Spring transactions with aspectj on Virgo [message #660934 is a reply to message #660769] |
Tue, 22 March 2011 12:18 |
Eclipse User |
|
|
|
Originally posted by: james.ractive.ch
Am 21.03.2011 15:18, schrieb Dmitry Sklyut:
Hi Dmitry
Thanks for your reply and your help.
> Very strange situation.
>
> Can you please provide a simplified test case? Set of bundles and we
> will look it over.
I put my modified greenpages app on bitbucket:
https://bitbucket.org/ractive/greenpages-plus
As mentioned previously, this app behaves exactly the same. When
clicking on the newly added "Add Listing" link on the top of the page
and submitting the form, addListing() is called which in turn calls
em.perist(). There is no error or anything, but the entry is just not
created. When using the debugger to step into the code, I can see in
org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionWrapper.checkForTransaction
that entityTransaction is null.
One should be able to import this project into eclipse and run it on a
configured virgo instance inside eclipse.
> Do your jpa services use interfaces or are they plain classes? How do
> you specify transactions on those services?
I changed the greenpages app in a way, there the entity implementation
(JpaListing) is annotated with @Entity and not using orm.xml as the
original app. The transactions are annotated in JpaDirectory.
Just let me know if you need any more information or help.
Best regards,
James
|
|
|
|
|
|
Re: Spring transactions with aspectj on Virgo [message #663338 is a reply to message #662561] |
Mon, 04 April 2011 16:56 |
Dmitry Sklyut Messages: 279 Registered: January 2010 |
Senior Member |
|
|
Ok. Here is a solution:
Change template.mf for greenpages.jpa to this
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: GreenPages JPA
Bundle-SymbolicName: greenpages.jpa
Bundle-Vendor: SpringSource Inc.
Bundle-Version: 2.3.0
Import-Template:
org.springframework.*;version="[3.0.3, 3.1)",
greenpages;version="[2.3, 2.4)",
javax.persistence.*;version="[2.0.3, 2.1.0)",
org.eclipse.persistence.*;version="[2.2.0, 2.3.0)",
org.apache.commons.dbcp.*;version="[1.2.2.osgi, 1.2.2.osgi]",
javax.sql;version="0"
Import-Bundle:
org.eclipse.persistence.core;version="[2.2.0, 2.3.0)",
org.eclipse.persistence.jpa;version="[2.2.0, 2.3.0)",
javax.persistence;version="[2.0.3, 2.1.0)"
Import-Package:
org.aspectj.lang;version="0",
org.aspectj.runtime.reflect;version="0"
Import-Library:
org.springframework.spring;version="[3.0.3, 3.1)"
Excluded-Exports:
greenpages.jpa
Excluded-Imports:
org.springframework.test.*,
org.junit.*
What changed?
1. Added Import-Library for spring lib. This can be cut down to only import required bundles or converted to a a list of Import-Package. I took the brute force approach.
Why? Bundlor only creates import packages for stuff that it can see. It does not deep scan all of the imports that you might need based on the spring config (i.e. <tx:annotation-driven/> and such.
2. Added imports for required aspectj packages.
3. Removed Import-Package for org.springframework packages that are covered by import-library.
Hope this helps.
Regards,
Dmitry
|
|
|
|
Powered by
FUDForum. Page generated in 0.03667 seconds