You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by tvogel <tv...@msn.com> on 2019/12/26 14:42:16 UTC

Multiple version of JPA managed classes in a karaf instance

I am successfully running multiple bundles, that provide classes with the
same name but different versions.

However when I try to do this with classes that provide JPA managed classes,
I am getting class cast exceptions (java.lang.ClassCastException:
some.package.ManagedClass cannot be cast to some.package.ManagedClass).

My changes to run multiple versions of JPA managed classes so far are:
1) update the version of the jar that provides these classes (3.2.1 ->
4.0.0)
2) ensure it uses the 4.0.0 version of supporting jars by using
Import-Package in pom
3) change the persistence.xml to have a different persistence-unit name
(pu_mysource3 -> pu_mysource4). 
 This file has <exclude-unlisted-classes>true</exclude-unlisted-classes>

Any suggestions on additional configuration changes necessary to run
multiple versions of JPA classes?

Thanks,
Timothy




--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Re: Multiple version of JPA managed classes in a karaf instance

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Tim,

FYI, you have http:proxy feature if you want a simple proxy:

https://github.com/apache/karaf/blob/master/manual/src/main/asciidoc/user-guide/webcontainer.adoc#http-proxy

Regards
JB

On 09/01/2020 15:59, tvogel wrote:
> Tim,
>   Thanks for explanation.  Your description of behavior matches my
> experience.
> 
>   Restructuring my code would likely be a significant undertaking.  Do you
> have any examples of your best practice already created in a public repo
> that I could review for estimating the effort?
> 
> In the "short term", I have used separate instances of karaf with nginx as a
> TCP reverse proxy to solve the issue.
> 
> Tim
> 
> 
> 
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Multiple version of JPA managed classes in a karaf instance

Posted by tvogel <tv...@msn.com>.
Tim,
  Thanks for explanation.  Your description of behavior matches my
experience.

  Restructuring my code would likely be a significant undertaking.  Do you
have any examples of your best practice already created in a public repo
that I could review for estimating the effort?

In the "short term", I have used separate instances of karaf with nginx as a
TCP reverse proxy to solve the issue.

Tim



--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Re: Multiple version of JPA managed classes in a karaf instance

Posted by Tim Ward <ti...@paremus.com>.
Hi,

The “tricky” part comes from the fact that the EntityManager Service API isn’t coupled to any of your domain classes, meaning that your “client” bundles can see EntityManager services registered by all of the persistence units, not just the one that they are wired to by Import-Package. Typically this will end up with with all the clients using the “first” service that they find, and some of them breaking with ClassCastException.

My advice would be to structure your code with the domain classes living inside a data access bundle (i.e. one which publishes a specific data access service). That way you can restrict the data access bundle to use the EntityManager that it provides, and you can rely on the service registry/uses constraints to fix the service visibility problem for you 100% of the time.


Best Regards,

Tim

> On 27 Dec 2019, at 14:18, tvogel <tv...@msn.com> wrote:
> 
> JB,
>  I'm using Aries feature in 4.0.10.  
> 
>  Does "tricky" mean the changes are not obvious or it takes experimentation
> on my specific setup to get working?
> 
> Thanks,
> Timothy 
> 
> 
> 
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html


Re: Multiple version of JPA managed classes in a karaf instance

Posted by tvogel <tv...@msn.com>.
JB,
  I'm using Aries feature in 4.0.10.  

  Does "tricky" mean the changes are not obvious or it takes experimentation
on my specific setup to get working?

Thanks,
Timothy 



--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Re: Multiple version of JPA managed classes in a karaf instance

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Tim,

If you talk about just JPA, using the right import package should work.

However, if you use Aries JPA, it could be tricky as the EntityManager
service can use a different version than yours.

Are you just using JPA API or also the JPA feature ?

Regards
JB

On 26/12/2019 15:42, tvogel wrote:
> I am successfully running multiple bundles, that provide classes with the
> same name but different versions.
> 
> However when I try to do this with classes that provide JPA managed classes,
> I am getting class cast exceptions (java.lang.ClassCastException:
> some.package.ManagedClass cannot be cast to some.package.ManagedClass).
> 
> My changes to run multiple versions of JPA managed classes so far are:
> 1) update the version of the jar that provides these classes (3.2.1 ->
> 4.0.0)
> 2) ensure it uses the 4.0.0 version of supporting jars by using
> Import-Package in pom
> 3) change the persistence.xml to have a different persistence-unit name
> (pu_mysource3 -> pu_mysource4). 
>  This file has <exclude-unlisted-classes>true</exclude-unlisted-classes>
> 
> Any suggestions on additional configuration changes necessary to run
> multiple versions of JPA classes?
> 
> Thanks,
> Timothy
> 
> 
> 
> 
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com