You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by iocanel <ca...@upstreamsystems.com> on 2010/05/10 08:45:15 UTC

Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!


cmoulliard wrote:
> 
> I think that the issue is related to Transaction but don't know how to
> solve it ?
> 

I don't know if that helps, but I've had similar issues with spring
transactions and camel pojos or servicemix beans. In the cases I've seen the
problem lies in the aop proxies spring creates on bean annotated with the
@Transactional annotations. 

The solution in my case was to use compile time weaving of spring-aspects
(using the maven aspectj plug-in).






-----
Ioannis Canellos
-- 
View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28508229.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by Charles Moulliard <cm...@gmail.com>.
Hi,

For the moment, I continue to use @Transaction annotation in the DAO
layer instead of the service layer. That means that I deploy two
bundles but keeping @Transaction in one to avoid this issue.

This is also how spring use this annotation in their Spring DM
examples (see GreenPage example) !! So they are aware that there is an
issue.

Kind regards,

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel/ServiceMix Committer

*******************************************************************
- Blog : http://cmoulliard.blogspot.com
- Twitter : http://twitter.com/cmoulliard
- Linkedlin : http://www.linkedin.com/in/charlesmoulliard



On Sun, Jun 6, 2010 at 9:15 PM, iocanel <ca...@upstreamsystems.com> wrote:
>
>
> cmoulliard wrote:
>>
>> I progress in my understanding of the issue. In fact, the commit does
>> not occur if the annotation @Transactional is defined in the Service
>> bundle instead of the DAO bundle. I think that there is an issue when
>> the service layer access the JPATransactionManager of Spring through
>> OSGI service and commit does not occur.
>>
>
> Hi Charles,
>
> I haven't heard from you on this issue and I was curious on how your
> research is going.
> I did some research on it myself, since I had similar issues in the past. I
> can't tell if the root cause in your case and mine is the same. For my case
> I came up to the conclusion that the issue is that "sometimes reflection
> does not work on cglib proxies". I also blogged about it. You can have a
> look at
> http://iocanel.blogspot.com/2010/06/spring-aop-and-reflection-pitfalls.html
> Spring AOP & Reflection issues
>
> -----
> Ioannis Canellos
> http://iocanel.blogspot.com/ http://iocanel.blogspot.com/
> --
> View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28793182.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by iocanel <ca...@upstreamsystems.com>.

cmoulliard wrote:
> 
> I progress in my understanding of the issue. In fact, the commit does
> not occur if the annotation @Transactional is defined in the Service
> bundle instead of the DAO bundle. I think that there is an issue when
> the service layer access the JPATransactionManager of Spring through
> OSGI service and commit does not occur.
> 

Hi Charles,

I haven't heard from you on this issue and I was curious on how your
research is going.
I did some research on it myself, since I had similar issues in the past. I
can't tell if the root cause in your case and mine is the same. For my case
I came up to the conclusion that the issue is that "sometimes reflection
does not work on cglib proxies". I also blogged about it. You can have a
look at 
http://iocanel.blogspot.com/2010/06/spring-aop-and-reflection-pitfalls.html
Spring AOP & Reflection issues 

-----
Ioannis Canellos
http://iocanel.blogspot.com/ http://iocanel.blogspot.com/ 
-- 
View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28793182.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by Charles Moulliard <cm...@gmail.com>.
I progress in my understanding of the issue. In fact, the commit does
not occur if the annotation @Transactional is defined in the Service
bundle instead of the DAO bundle. I think that there is an issue when
the service layer access the JPATransactionManager of Spring through
OSGI service and commit does not occur.

Kind regards,

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel/ServiceMix Committer

*******************************************************************
- Blog : http://cmoulliard.blogspot.com
- Twitter : http://twitter.com/cmoulliard
- Linkedlin : http://www.linkedin.com/in/charlesmoulliard



On Tue, May 11, 2010 at 10:39 AM, iocanel <ca...@upstreamsystems.com> wrote:
>
>
> cmoulliard wrote:
>>
>> The transaction is initiated but not committed
>>
>
> Then it wouldn't hurt to try the my solution :-)
>
>
>
> -----
> Ioannis Canellos
> --
> View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28521451.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by iocanel <ca...@upstreamsystems.com>.

cmoulliard wrote:
> 
> The transaction is initiated but not committed 
> 

Then it wouldn't hurt to try the my solution :-)



-----
Ioannis Canellos
-- 
View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28521451.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by Charles Moulliard <cm...@gmail.com>.
The transaction is initiated but not committed :

10:17:22,571 | DEBUG | tenerContainer-1 | JtaTransactionManager
    | stractPlatformTransactionManager  371 | Creating new transaction
with name [com.goodyear.emea.gicl.esb.service.Persistence.save]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
10:17:22,571 | DEBUG | tenerContainer-1 | EntityManagerFactoryUtils
    | rm.jpa.EntityManagerFactoryUtils  194 | Opening JPA
EntityManager
10:17:22,571 | DEBUG | tenerContainer-1 | EntityManagerFactoryUtils
    | rm.jpa.EntityManagerFactoryUtils  199 | Registering transaction
synchronization for JPA EntityManager
10:17:24,540 | DEBUG | tenerContainer-1 | EntityManagerFactoryUtils
    | rm.jpa.EntityManagerFactoryUtils  313 | Closing JPA
EntityManager
10:17:24,540 | DEBUG | tenerContainer-1 | JtaTransactionManager
    | stractPlatformTransactionManager  730 | Initiating transaction
commit
10:17:24,540 | INFO  | tenerContainer-1 | route12
    | rg.apache.camel.processor.Logger  212 | >>> Message saved in the
DB : queue_validated_ID_dell-charles-1187-1273561858774-2_6_1_1_2


Kind regards,

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel Committer

*******************************************************************
- Blog : http://cmoulliard.blogspot.com
- Twitter : http://twitter.com/cmoulliard
- Linkedlin : http://www.linkedin.com/in/charlesmoulliard



On Tue, May 11, 2010 at 9:36 AM, iocanel <ca...@upstreamsystems.com> wrote:
>
>
> cmoulliard wrote:
>>
>> I don't have any errors except that the transaction is not started
>> with begin / commit. Even if I use EclipseLink or Hibernate JPA, I see
>> in the stack trace the SQL SELECT done one the DB but no insert
>>
>
> Hi Charles,
>
> If the problem is that the transaction is not started (resulting in an error
> that indicates that a transaction is not active) then my solution will not
> solve your problem. In this case we should review the overall configuration.
>
>
> -----
> Ioannis Canellos
> --
> View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28520916.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by iocanel <ca...@upstreamsystems.com>.

cmoulliard wrote:
> 
> I don't have any errors except that the transaction is not started
> with begin / commit. Even if I use EclipseLink or Hibernate JPA, I see
> in the stack trace the SQL SELECT done one the DB but no insert
> 

Hi Charles,

If the problem is that the transaction is not started (resulting in an error
that indicates that a transaction is not active) then my solution will not
solve your problem. In this case we should review the overall configuration.


-----
Ioannis Canellos
-- 
View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28520916.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by Charles Moulliard <cm...@gmail.com>.
I don't have any errors except that the transaction is not started
with begin / commit. Even if I use EclipseLink or Hibernate JPA, I see
in the stack trace the SQL SELECT done one the DB but no insert

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel Committer

*******************************************************************
- Blog : http://cmoulliard.blogspot.com
- Twitter : http://twitter.com/cmoulliard
- Linkedlin : http://www.linkedin.com/in/charlesmoulliard



On Tue, May 11, 2010 at 8:42 AM, iocanel <ca...@upstreamsystems.com> wrote:
>
>
> cmoulliard wrote:
>>
>> I will have a look on what you propose and test it in SMX4.x.
>>
>> I have made tests without using @Transactional and configuring spring
>> with
>> org.springframework.transaction.interceptor.TransactionProxyFactoryBean
>> but insert does not occur too in DB. I have no idea why the commit is
>> not done on the transaction.
>>
>
> Hi Charles,
>
> have you tried to debug in order to determine the exact nature of the
> problem?
>
> -----
> Ioannis Canellos
> --
> View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28520495.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by iocanel <ca...@upstreamsystems.com>.

cmoulliard wrote:
> 
> I will have a look on what you propose and test it in SMX4.x.
> 
> I have made tests without using @Transactional and configuring spring
> with
> org.springframework.transaction.interceptor.TransactionProxyFactoryBean
> but insert does not occur too in DB. I have no idea why the commit is
> not done on the transaction.
> 

Hi Charles,

have you tried to debug in order to determine the exact nature of the
problem? 

-----
Ioannis Canellos
-- 
View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28520495.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by Charles Moulliard <cm...@gmail.com>.
I will have a look on what you propose and test it in SMX4.x.

I have made tests without using @Transactional and configuring spring
with org.springframework.transaction.interceptor.TransactionProxyFactoryBean
but insert does not occur too in DB. I have no idea why the commit is
not done on the transaction.

Best regards,

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel Committer

*******************************************************************
- Blog : http://cmoulliard.blogspot.com
- Twitter : http://twitter.com/cmoulliard
- Linkedlin : http://www.linkedin.com/in/charlesmoulliard



On Mon, May 10, 2010 at 1:44 PM, iocanel <ca...@upstreamsystems.com> wrote:
>
>
> cmoulliard wrote:
>>
>> Thxs for the info. We have the same issue with Hibernate JPA. So
>> definitively, this is related to aop spring proxies.
>>
>> Can you provide us more info about what you have done and which
>> bundles you have deployed ?
>>
>> Kind regards,
>>
>> Charles Moulliard
>>
>
> I am using servicemix 3.3.x so there are not much I can tell you about the
> bundles :-(
>
> I will try to give you as much information I can regarding the problem and
> our configuration.
>
> Our problem was that whenever spring was creating CGLIB proxies (dynamic
> proxies didn't work for at all) both camel and servicemix igonred the other
> annotations. This resulted in various exceptions.
>
> Example Having a servicemix bean proxied by CGLIB prevented the injection of
> Delivery Channel (which was annotated with the Resource annotation) causing
> a NPE during execution.
>
> So we had to get rid of CGLIB proxies:
>
> Solution 1: Do not use mix servicemix/camel with @Transactional annotations.
> In your example this would be as simple as to remove the @Transactional
> annotation from PersistenceImpl and put it inside the sap document dao (or
> any other bean that wouldn't contain both types of annotations).
>
> Solution 2: Totally remove CGLIB proxies and weave the @Transactional
> behavior on compile time. This was the solution I prefered and we did it
> like this:
>
> <!-- Inside the Spring Context we set annotation-driven mode to aspectj.
> This mode doesn't use proxies -->
> <tx:annotation-driven mode="aspectj"
> transaction-manager="transactionManager"/>
>
> <!-- Inside the pom.xml, we use aspectj plugin to weave spring-aspects. This
> will weave the @Transaction on compile time -->
>           <plugin>
>                <groupId>org.codehaus.mojo</groupId>
>                <artifactId>aspectj-maven-plugin</artifactId>
>               <version>1.3</version>
>                <executions>
>                    <execution>
>                        <goals>
>                            <goal>compile</goal>
>                            <goal>test-compile</goal>
>                        </goals>
>                    </execution>
>                </executions>
>                <configuration>
>                    <outxml>true</outxml>
>                    <aspectLibraries>
>                        <aspectLibrary>
>                            <groupId>org.springframework</groupId>
>                            <artifactId>spring-aspects</artifactId>
>                        </aspectLibrary>
>                    </aspectLibraries>
>                    <source>1.5</source>
>                    <target>1.5</target>
>                </configuration>
>            </plugin>
>
>
> I hope that this helps. Let me know if you wish additional details.
>
>
>
>
>
>
> -----
> Ioannis Canellos
> --
> View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28510533.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by iocanel <ca...@upstreamsystems.com>.

cmoulliard wrote:
> 
> Thxs for the info. We have the same issue with Hibernate JPA. So
> definitively, this is related to aop spring proxies.
> 
> Can you provide us more info about what you have done and which
> bundles you have deployed ?
> 
> Kind regards,
> 
> Charles Moulliard
> 

I am using servicemix 3.3.x so there are not much I can tell you about the
bundles :-(

I will try to give you as much information I can regarding the problem and
our configuration.

Our problem was that whenever spring was creating CGLIB proxies (dynamic
proxies didn't work for at all) both camel and servicemix igonred the other
annotations. This resulted in various exceptions.

Example Having a servicemix bean proxied by CGLIB prevented the injection of
Delivery Channel (which was annotated with the Resource annotation) causing
a NPE during execution.

So we had to get rid of CGLIB proxies:

Solution 1: Do not use mix servicemix/camel with @Transactional annotations.
In your example this would be as simple as to remove the @Transactional
annotation from PersistenceImpl and put it inside the sap document dao (or
any other bean that wouldn't contain both types of annotations).

Solution 2: Totally remove CGLIB proxies and weave the @Transactional
behavior on compile time. This was the solution I prefered and we did it
like this:

<!-- Inside the Spring Context we set annotation-driven mode to aspectj.
This mode doesn't use proxies -->
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager"/>

<!-- Inside the pom.xml, we use aspectj plugin to weave spring-aspects. This
will weave the @Transaction on compile time -->
           <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
               <version>1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outxml>true</outxml>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>                            
                        </aspectLibrary>
                    </aspectLibraries>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>


I hope that this helps. Let me know if you wish additional details.






-----
Ioannis Canellos
-- 
View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28510533.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Data not inserted into DB (Camel Bean / EclipseLink / Spring DM / SMX 4.2) !!

Posted by Charles Moulliard <cm...@gmail.com>.
Thxs for the info. We have the same issue with Hibernate JPA. So
definitively, this is related to aop spring proxies.

Can you provide us more info about what you have done and which
bundles you have deployed ?

Kind regards,

Charles Moulliard

Senior Enterprise Architect (J2EE, .NET, SOA)
Apache Camel Committer

*******************************************************************
- Blog : http://cmoulliard.blogspot.com
- Twitter : http://twitter.com/cmoulliard
- Linkedlin : http://www.linkedin.com/in/charlesmoulliard



On Mon, May 10, 2010 at 8:45 AM, iocanel <ca...@upstreamsystems.com> wrote:
>
>
> cmoulliard wrote:
>>
>> I think that the issue is related to Transaction but don't know how to
>> solve it ?
>>
>
> I don't know if that helps, but I've had similar issues with spring
> transactions and camel pojos or servicemix beans. In the cases I've seen the
> problem lies in the aop proxies spring creates on bean annotated with the
> @Transactional annotations.
>
> The solution in my case was to use compile time weaving of spring-aspects
> (using the maven aspectj plug-in).
>
>
>
>
>
>
> -----
> Ioannis Canellos
> --
> View this message in context: http://old.nabble.com/Data-not-inserted-into-DB-%28Camel-Bean---EclipseLink---Spring-DM---SMX--4.2%29-%21%21-tp28475358p28508229.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>