Yes -- only some configuration properties can be set via the
createEntityManager() call. I forget exactly which they are; I believe
that the JavaDoc for the method in OpenJPAEntityManagerFactory goes
into more detail.

The connection URL must be constant across the entire EMF.

If you need to use different URLs for different credentials, you might
want to look at writing your own DataSource implementation. You can
then specify the full class name of your DataSource implementation in
the openjpa.ConnectionFactory property.

Also, bear in mind that OpenJPA's data cache does not partition based
on database credentials, so if the different credentials provide
access to different data sets, you should disable data caching (the
default).

-Patrick

On 10/1/07, Janap <[EMAIL PROTECTED]> wrote:
>
> I managed to partially configure the EntityManager
>
> Case 1 :
>
> persistence.xml
>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"; version="1.0">
> <persistence-unit name="myPersistence"  transaction-type="RESOURCE_LOCAL">
>         <provider>
>             org.apache.openjpa.persistence.PersistenceProviderImpl
>         </provider>
>         <class>test.myClass</class>
>         <properties>
>             <property name="openjpa.ConnectionURL"
> value="jdbc:oracle:thin:@server:1521:db"/>
>             <property name="openjpa.ConnectionDriverName"
> value="oracle.jdbc.driver.OracleDriver"/>
>             <property name="openjpa.Log"
> value="DefaultLevel=TRACE,Tool=TRACE"/>
>         </properties>
> </persistence-unit>
> </persistence>
>
> and ConnectionManager class
>
>         EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("myPersistence");
>         System.out.println("persistence factory setup successfully" + emf);
>         HashMap myProperties = new HashMap();
>         myProperties.put("openjpa.ConnectionUserName",user);
>         myProperties.put("openjpa.ConnectionPassword",pwd);
>
>         EntityManager em = emf.createEntityManager(myProperties);
>
> this works without problem, I could also persist one of my entity beans.
>
> Now when I try to remove Connection URL from persistence.xml and move it to
> the ConnectionManager class
>
> myProperties.put("openjpa.ConnectionURL","jdbc:oracle:thin:@server:1521:db");
> it throws an exception saying
>
> <4|false|0.9.6-incubating> org.apache.openjpa.persistence.ArgumentException:
> Missing getter for property "ConnectionURL" in type "class
> org.apache.openjpa.persistence.EntityManagerImpl".
>         at org.apache.openjpa.util.ImplHelper.getGetter(ImplHelper.java:65)
>         at org.apache.openjpa.util.ImplHelper.getSetter(ImplHelper.java:75)
>         at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:214)
>         at
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:52)
>         at test.ConnectionManager.doGet(ConnectionManager.java:29)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
>         at
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
>         at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
>         at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
>         at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.NoSuchMethodException:
> org.apache.openjpa.persistence.EntityManagerImpl.getConnectionURL()
>         at java.lang.Class.getMethod(Class.java:1581)
>         at org.apache.openjpa.util.ImplHelper.getGetter(ImplHelper.java:60)
>
>
>
>
> Janap wrote:
> >
> > Thx for the replies. So as I understand , I can create
> > EntityManagerFactory when my server starts by giving it a persistence unit
> > name and WITHOUT giving it a username and password which are neccessary to
> > make a DB connection?
> >
> > For every user who logs in , i can create an EntityManager by passing the
> > connection parameters in the map. This EntityManager, I can either keep it
> > in session per user or create everytime a transaction is needed.
> >
> > I will now start making an example and let you know what has happened!
> >
> > Janap
> >
> >
> >
> > Alessandro Ferrucci-3 wrote:
> >>
> >> There is no obligatory contract between the EntityManagerFactory and
> >> whatever container/environment you are in.  The EntityManagerFactory
> >> is...just that..a factory of EntityManagers.  Read:
> >> http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_overview_emfactory_obtainto
> >> see how to retrieve an EntityManager, you must pass in a Map of
> >> attributes that your EntityManager will be configured with to talk to the
> >> DB
> >>
> >>
> >> mainly:
> >>
> >>    -
> >>
> >>    openjpa.ConnectionUserName
> >>    -
> >>
> >>    openjpa.ConnectionPassword
> >>    -
> >>
> >>    openjpa.ConnectionRetainMode
> >>    -
> >>
> >>    openjpa.TransactionMode
> >>    -
> >>
> >>    openjpa.<property>, where *<property> * is any JavaBean property of
> >>    the
> >> org.apache.openjpa.persistence.OpenJPAEntityManager<http://openjpa.apache.org/docs/latest/javadoc/org/apache/openjpa/persistence/OpenJPAEntityManager.html>.
> >>
> >>
> >> Also of importance is this:
> >>
> >> http://openjpa.apache.org/docs/latest/manual/manual.html#jpa_overview_persistence_xml
> >>
> >> this tells you how to configure a certain factory in non-EE settings.
> >>
> >>
> >> HTH
> >>
> >> Alessandro Ferrucci.
> >>
> >>
> >>
> >
> >
>
> --
> View this message in context: 
> http://www.nabble.com/EntityManagerFactory-configure-tf4547543.html#a12980798
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>


-- 
Patrick Linskey
202 669 5907

Reply via email to