You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by paulvitic <pa...@vektortelekom.com> on 2011/03/29 11:26:55 UTC

Merging modular persistence units

Hi,

I am using openjpa 1.2.2 with spring. My project has multiple units that
have entity classes. I wanted to be able to declare my persistence units in
persistence.xml files within their own packages and merge these at runtime.
There is a nice article that demonstrates how to do this.
(http://labs.bsb.com/2010/11/configuring-modular-jpa-applications-with-spring/)
which works except that when I try to enhance my classes at loadtime with
openjpa enhancer (this is the enhancement strategy I have to adopt for
reasons beyond the scope of this post) I run into trouble.

The problem seems to be that at classload time openjpa enhancer is not aware
of the persistence classes that will later going to be found by spring and
it only checks what is available on the running applications
META/persistence.xml file. Since the application does not support
RuntimeUnenhancedClasses this later causes error. 

Is there a way to provide the openjpa loadtime enhancer with locations of
multiple persitence xml files in the classpath so that it enhances the
classes declared in all of these?

Thank you.    

--
View this message in context: http://openjpa.208410.n2.nabble.com/Merging-modular-persistence-units-tp6218352p6218352.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Merging modular persistence units

Posted by paulvitic <pa...@vektortelekom.com>.
Thank you for the reply,

>> this is the enhancement strategy I have to adopt for reasons beyond the 
scope of this post 
> I don't want to get this post off track, but I am interested in hearing
> what 
the problems were that you encountered with build time enhancement. 
Our application uses legacy libraries which are also used by legacy
applications. The legacy application employs a particular enhancement
strategy which utilizes a custom built java agent. This agent looks for xml
files with a particular name (which are actually invalid persitence xml
files carrying only class elements) at a particular location in the
classpath and merges all of these to form a valid persitence.xml and places
it under META-INF and than lets jpa enhancer to do loadtime enhancement. We
could probably continue to use this custom agent but I am searching for more
elegant way to achieve this. 

>Now down to my recommendation. This advise assumes that you're using the
-javaagent for enhancement.? 
Yes I am using openjpa javaagent.

>You could create a "root" persistence unit in the default
location(META-INF/persistence. xml) that will be used only for enhancement.
If you do not list any persistent types in the  list, we will enhance all
Entities that are encountered at load time. I think this approach should
work for you... just as long as you don't have different openjpa.DetachState
settings across your persistence units. 

-javaagent:[path-to-openjpa-jar].jar=p=META-INF/persistence.xml#enhance-pu 

Thanks I will try this approach and come back with feedback.

Paul


--
View this message in context: http://openjpa.208410.n2.nabble.com/Merging-modular-persistence-units-tp6218352p6222043.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Merging modular persistence units

Posted by Rick Curtis <cu...@gmail.com>.
> Is there a way to provide the openjpa loadtime enhancer with locations of
multiple persitence xml files in the classpath so that it enhances the
classes declared in all of these?
I scanned the code quickly and I don't believe so.


> this is the enhancement strategy I have to adopt for reasons beyond the
scope of this post
I don't want to get this post off track, but I am interested in hearing what
the problems were that you encountered with build time enhancement.

Now down to my recommendation. This advise assumes that you're using the
-javaagent for enhancement.?

You could create a "root" persistence unit in the default
location(META-INF/persistence.
xml) that will be used only for enhancement. If you do not list any
persistent types in the <class> list, we will enhance all Entities that are
encountered at load time. I think this approach should work for you... just
as long as you don't have different openjpa.DetachState settings across your
persistence units.

-javaagent:[path-to-openjpa-jar].jar=p=META-INF/persistence.xml#enhance-pu

Thanks,
Rick


On Tue, Mar 29, 2011 at 4:26 AM, paulvitic <pa...@vektortelekom.com> wrote:

> Hi,
>
> I am using openjpa 1.2.2 with spring. My project has multiple units that
> have entity classes. I wanted to be able to declare my persistence units in
> persistence.xml files within their own packages and merge these at runtime.
> There is a nice article that demonstrates how to do this.
> (
> http://labs.bsb.com/2010/11/configuring-modular-jpa-applications-with-spring/
> )
> which works except that when I try to enhance my classes at loadtime with
> openjpa enhancer (this is the enhancement strategy I have to adopt for
> reasons beyond the scope of this post) I run into trouble.
>
> The problem seems to be that at classload time openjpa enhancer is not
> aware
> of the persistence classes that will later going to be found by spring and
> it only checks what is available on the running applications
> META/persistence.xml file. Since the application does not support
> RuntimeUnenhancedClasses this later causes error.
>
> Is there a way to provide the openjpa loadtime enhancer with locations of
> multiple persitence xml files in the classpath so that it enhances the
> classes declared in all of these?
>
> Thank you.
>