Hi jeff,
The bootstrapping is described in 7.2 of the specification. The PU
name is specified by the call to
Persistence.createEntityManagerFactory(String PUName).
The technique I was describing is the case where you have a compiled
program that hard-codes the PUName and you want to change the PU
definition. But it's easier to pass the PUName to your program as a
command line parameter or in a configuration file and then use that
name in the createEntityManagerFactory call.
Craig
package javax.persistence;
import java.util.*;
...
/**
* Bootstrap class that is used to obtain an
* EntityManagerFactory.
*/
public class Persistence {
/**
* Create and return an EntityManagerFactory for the
* named persistence unit.
*
* @param persistenceUnitName The name of the persistence unit
* @return The factory that creates EntityManagers configured
* according to the specified persistence unit
*/
public static EntityManagerFactory createEntityManagerFac-
tory(String persistenceUnitName) {...}
/**
* Create and return an EntityManagerFactory for the
* named persistence unit using the given properties.
*
* @param persistenceUnitName The name of the persistence unit
* @param props Additional properties to use when creating the
* factory. The values of these properties override any values
* that may have been configured elsewhere.
* @return The factory that creates EntityManagers configured
* according to the specified persistence unit.
*/
public static EntityManagerFactory createEntityManagerFac-
tory(String persistenceUnitName, Map properties) {...}
On Feb 27, 2007, at 2:02 PM, jeff wrote:
> hi jon,
>
> okay, how do i do that? i see a version of createEntityManager()
> that takes a Map of "properties", but the javadocs don't say how i
> could use that to affect the selection of a particular persistence
> unit.
>
> Jon Miller <jemiller_at_uchicago.edu> wrote:
> Wouldn't you just select the one you want by name when you call
> Persistence.createEntityManager()?
>
> Jon
>
> ----- Original Message -----
> From: "Craig L Russell"
> To:
> Sent: Tuesday, February 27, 2007 3:43 PM
> Subject: Re: choosing persistence unit at runtime?
>
>
> > You might consider putting the persistence.xml file into a jar file
> > of its own (a different jar file for each persistence.xml you want).
> > Then, select the jar file (with its persistence.xml inside) by
> > prepending it to your class path.
> >
> > Craig
> >
> > On Feb 27, 2007, at 1:23 PM, jeff wrote:
> >
> >> if i am using java persistence stand alone, am i able to choose the
> >> persistence unit at runtime?
> >>
> >> i can't see how to do this, because it appears that the
> >> persistence.xml file is read from the classpath.
> >>
> >> any ideas?
> >> thanks.
> >>
> >>
> >>
> >> The fish are biting.
> >> Get more visitors on your site using Yahoo! Search Marketing.
> >
> > Craig Russell
> > Architect, Sun Java Enterprise System http://java.sun.com/
> products/jdo
> > 408 276-5638 mailto:Craig.Russell_at_sun.com
> > P.S. A good JDO? O, Gasp!
> >
> >
>
>
> Access over 1 million songs - Yahoo! Music Unlimited.
Craig Russell
Architect, Sun Java Enterprise System
http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!
- application/pkcs7-signature attachment: smime.p7s