You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Brian H1 <bd...@yahoo.com> on 2008/03/28 16:40:36 UTC

Re: Specifying the location of the persistence.xml file at runtime

Hi,

I'm wondering if I could get some clarification on this method from someone
who's used this?  I always seem to get a null back.  If I make call this
method 
URL xxx = getClass().getResource("/META-INF/persistence.xml");, I get a
valid url that has a fully qualified path to the persistence.xml.  But, I
haven't been able to turn around and use that path as the resource in the
createEntityManagerFactory method.  Is the string "resource" parameter meant
to be a file path?  If not, what?

Thanks
Brian




Patrick Linskey-2 wrote:
> 
> Hi,
> 
> There's no portable way to specify a location other than
> /META-INF/persistence.xml. However, you could dynamically create a jar
> with your persistence.xml in the right location and then create a
> ClassLoader with this jar in it.
> 
> Alternately, you could use the
> OpenJPAPersistence.createEntityManagerFactory(String puName, String
> rsrc) method.
> 
> -Patrick
> 
> On Jan 18, 2008 1:10 AM, zzzz8 <zz...@netzero.net> wrote:
>>
>> Is there any way I can specify the location of the persistence.xml file
>> at
>> runtime for my Java SE JPA app, before I create my entitymanagerfactory?
>> There are times when I will not place the persistence.xml in
>> META-INF/persistence.xml in my classpath... Or is this not possible? The
>> really ugly way would be for me to write a method that reads in the
>> properties of the specified persistence.xml config file at runtime - then
>> assign it to the properties map when call the static method
>> createentitymanagerfactory of the Persistence class - but that's really
>> ugly
>> and probably not portable. Does anyone have any ideas regarding this
>> issue?
>> TIA.
>> --
>> View this message in context:
>> http://www.nabble.com/Specifying-the-location-of-the-persistence.xml-file-at-runtime-tp14948023p14948023.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 

-- 
View this message in context: http://www.nabble.com/Specifying-the-location-of-the-persistence.xml-file-at-runtime-tp14948023p16351805.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Specifying the location of the persistence.xml file at runtime

Posted by hivolt <ed...@alumni.cmu.edu>.
Hi Brian,
<br><br>The method 
<br><a href="http://java.sun.com/javaee/5/docs/api/javax/persistence/Persistence.html#createEntityManagerFactory(java.lang.String,%20java.util.Map)" target="_top" rel="nofollow">createEntityManagerFactory(String persistenceUnitName, Map properties)</a><br><br>takes a Map as the second argument, rather than a URL.
<br><br><blockquote class="quote light-black dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Brian H1 wrote:</div>
<div class="quote-message shrinkable-quote">Hi,
<br><br>I'm wondering if I could get some clarification on this method from someone who's used this? &nbsp;I always seem to get a null back. &nbsp;If I make call this method 
<br>URL xxx = getClass().getResource(&quot;/META-INF/persistence.xml&quot;);, I get a valid url that has a fully qualified path to the persistence.xml. &nbsp;But, I haven't been able to turn around and use that path as the resource in the createEntityManagerFactory method. &nbsp;Is the string &quot;resource&quot; parameter meant to be a file path? &nbsp;If not, what?
<br><br>Thanks
<br>Brian
<br><br><br><br><blockquote class="quote light-black dark-border-color"><div class="quote light-border-color">
<div class="quote-author" style="font-weight: bold;">Patrick Linskey-2 wrote:</div>
<div class="quote-message shrinkable-quote">Hi,
<br><br>There's no portable way to specify a location other than
<br>/META-INF/persistence.xml. However, you could dynamically create a jar
<br>with your persistence.xml in the right location and then create a
<br>ClassLoader with this jar in it.
<br><br>Alternately, you could use the
<br>OpenJPAPersistence.createEntityManagerFactory(String puName, String
<br>rsrc) method.
<br><br>-Patrick
<br><br>On Jan 18, 2008 1:10 AM, zzzz8 &lt;zzzz8@netzero.net&gt; wrote:
<br>&gt;
<br>&gt; Is there any way I can specify the location of the persistence.xml file at
<br>&gt; runtime for my Java SE JPA app, before I create my entitymanagerfactory?
<br>&gt; There are times when I will not place the persistence.xml in
<br>&gt; META-INF/persistence.xml in my classpath... Or is this not possible? The
<br>&gt; really ugly way would be for me to write a method that reads in the
<br>&gt; properties of the specified persistence.xml config file at runtime - then
<br>&gt; assign it to the properties map when call the static method
<br>&gt; createentitymanagerfactory of the Persistence class - but that's really ugly
<br>&gt; and probably not portable. Does anyone have any ideas regarding this issue?
<br>&gt; TIA.
<br>&gt; --
<br>&gt; View this message in context: <a href="http://www.nabble.com/Specifying-the-location-of-the-persistence.xml-file-at-runtime-tp14948023p14948023.html" target="_top" rel="nofollow">http://www.nabble.com/Specifying-the-location-of-the-persistence.xml-file-at-runtime-tp14948023p14948023.html</a><br>&gt; Sent from the OpenJPA Users mailing list archive at Nabble.com.
<br>&gt;
<br>&gt;
<br><br><br><br>-- 
<br>Patrick Linskey
<br>202 669 5907
</div>
</div></blockquote>
</div>
</div></blockquote>

-- 
View this message in context: http://n2.nabble.com/Specifying-the-location-of-the-persistence.xml-file-at-runtime-tp210313p2522768.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.