You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Kevin Lohmann <ke...@d-velop.de> on 2008/09/18 16:36:12 UTC

Using JPA with OSGi

Hi *,

we're trying to use JPA within an OSGi-Application. We decided to use
OpenJPA with Derby.

We have a bundle A, which implements an service-interface that offers an
EntityManager. The interface-method has no parameters.

Another bundle B uses this service to retrieve an EntityManager and to
persist class C (which is located in bundle B and which package is just
private).

So bundle A knows nothing about class C, the EntityManager is created
with not knowing about C too. The consequence is that the EntityManager
don't persist C because C is not enhanced.

We found out that with BuddyPolicy from equinox-framework, things get
work. But we don't want to have framework-specific things.
Another possibility is using 'DynamicImport-Package: *' in bundle A and
to export class C in bundle B - but thats an option, which we consider
to be dirty.
We played with classloading-mechanism, but those games didn't work.

So, how do other people use (Open)JPA within OSGi? Is it maybe better,
to switch to Hibernate with database XXX? 

Yet, there must be a solution for it!?

Thanks for reply,
 Kevin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Using JPA with OSGi

Posted by "peter.doornbosch" <pe...@gmail.com>.
> Another bundle B uses this service to retrieve an EntityManager and to
> persist class C (which is located in bundle B and which package is  
> just
> private).

This is not going to work. B must export the package C is in.

> So bundle A knows nothing about class C, the EntityManager is created
> with not knowing about C too. The consequence is that the  
> EntityManager
> don't persist C because C is not enhanced.

hmm, i think that actually the EM is not going to persist C because it  
doesn't know its class.
Enhancing can be a problem though, because this is done on a  
classloader and because of Murphy's laws, probably on the wrong one.  
And then there is the issue that you might be too late and somebody is  
already using the non-enhanced classes. I did a lot of debugging with  
OpenJPA to find out how this all works, and my conclusion is that  
trying to make enhancing on the fly work, is not worth the trouble.  
Just enhance the classes compile time. Of course, this has the  
disadvantage that you "sneak in" dependency on OpenJPA (in the sense  
that it is only going to work with the OpenJPA persistence provider),  
but i can live with that.


Hth.
Regards,
Peter.

> We found out that with BuddyPolicy from equinox-framework, things get
> work. But we don't want to have framework-specific things.
> Another possibility is using 'DynamicImport-Package: *' in bundle A  
> and
> to export class C in bundle B - but thats an option, which we consider
> to be dirty.
> We played with classloading-mechanism, but those games didn't work.
>
> So, how do other people use (Open)JPA within OSGi? Is it maybe better,
> to switch to Hibernate with database XXX?
>
> Yet, there must be a solution for it!?
>
> Thanks for reply,
> Kevin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


AW: Using JPA with OSGi

Posted by Kevin Lohmann <ke...@d-velop.de>.
Hi Peter,

> See 
> http://blog.luminis.nl/roller/luminis/entry/jpa_persistence_in
> _osgi_with 
>   and 
> http://blog.luminis.nl/roller/luminis/entry/persistence_in_osg
> i_with_openjpa 
> .
i've read your states already. But...

> Just enhance the classes compile time.
... thats not an option for us. We don't want and do not know about
every entity at compile time! We want to allow every possible bundle to
persist its classes.

> B must export the package C is in.
Is it true? Is it a must? That would be a very sad realization!

Cheers,
 Kevin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Using JPA with OSGi

Posted by "peter.doornbosch" <pe...@gmail.com>.
Hi Kevin,

> So, how do other people use (Open)JPA within OSGi?

See http://blog.luminis.nl/roller/luminis/entry/jpa_persistence_in_osgi_with 
  and http://blog.luminis.nl/roller/luminis/entry/persistence_in_osgi_with_openjpa 
.

Although the code samples are simple (maybe even simplistic), this is  
how i've used OpenJPA in a real world project.

Note that i'm not publishing an EntityManager service. I prefer to  
hide the persistence details behind a business interface.

> Is it maybe better,
> to switch to Hibernate with database XXX?

I wouldn't recommand that. Using a standard is always better,  
especially when that standard is widely used - and JPA is.

Regards,
Peter
>
>
> Yet, there must be a solution for it!?
>
> Thanks for reply,
> Kevin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Using JPA with OSGi

Posted by "Richard S. Hall" <he...@ungoverned.org>.
Is it a coincidence that I just happen to get this announcement today:

    http://www.dynamicjava.org/projects/jsr-api/jpa-osgi

Not sure if it addresses your concern or not, but it sounds like it might.

-> richard

Kevin Lohmann wrote:
> Hi *,
>
> we're trying to use JPA within an OSGi-Application. We decided to use
> OpenJPA with Derby.
>
> We have a bundle A, which implements an service-interface that offers an
> EntityManager. The interface-method has no parameters.
>
> Another bundle B uses this service to retrieve an EntityManager and to
> persist class C (which is located in bundle B and which package is just
> private).
>
> So bundle A knows nothing about class C, the EntityManager is created
> with not knowing about C too. The consequence is that the EntityManager
> don't persist C because C is not enhanced.
>
> We found out that with BuddyPolicy from equinox-framework, things get
> work. But we don't want to have framework-specific things.
> Another possibility is using 'DynamicImport-Package: *' in bundle A and
> to export class C in bundle B - but thats an option, which we consider
> to be dirty.
> We played with classloading-mechanism, but those games didn't work.
>
> So, how do other people use (Open)JPA within OSGi? Is it maybe better,
> to switch to Hibernate with database XXX? 
>
> Yet, there must be a solution for it!?
>
> Thanks for reply,
>  Kevin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org