openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: Override "jta-data-source" with system properties?
Date Mon, 19 Jul 2010 18:03:04 GMT
The test was pretty basic :
            String driver = "", url = "", user = "", pass = "";

            Map<Object, Object> props = new HashMap<Object, Object>();
            // props.put("openjpa.ConnectionFactoryName", "");
            props.put("javax.persistence.jtaDataSource", "");
            props.put("openjpa.ConnectionDriverName", driver);
            props.put("openjpa.ConnectionURL", url);
            props.put("openjpa.ConnectionUserName", user);
            props.put("openjpa.ConnectionPassword", pass);

            emf = Persistence.createEntityManagerFactory("harald", props);
            assertNotNull(emf);
            EntityManager em = emf.createEntityManager();
            assertNotNull(em);
            em.close();
            emf.close();

persistence.xml :
     <persistence-unit name="harald" transaction-type="RESOURCE_LOCAL">
        <jta-data-source>jdbc/notReal</jta-data-source>
        <class>harald.Person</class>
        <properties>
            <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
        </properties>
    </persistence-unit>

What's the exact error message you're getting?

I'll go back and run with 2.0.0, I tried this with a 2.0.1 snapshot which
has a few changes.

-mike


On Mon, Jul 19, 2010 at 10:42 AM, Harald Wellmann <
Harald.Wellmann@multi-m.de> wrote:

>
> Hmm, can you be a bit more specific about your "quick test"? How did you
> set
> your datasource properties then?
> Setting these two properties to "", I keep getting an exception regarding a
> non-existent transaction manager.
>
> Meanwhile, I've found a solution that works for me.
>
> persistence.xml:
>
>  <persistence-unit name="mymodel">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>    <jta-data-source>jdbc/MyDataSource</jta-data-source>
>     <class>...</class>
>  </persistence-unit>
>
>
> Test fixture set-up:
>
>        Map<String, Object> props = new HashMap<String, Object>();
>
>        props.put("javax.persistence.jdbc.driver", driver);
>        props.put("javax.persistence.jdbc.url", url);
>        props.put("javax.persistence.jdbc.user", user);
>        props.put("javax.persistence.jdbc.password", password);
>
>        // Properties for the alternate non-jta-data-source. We need to set
> these
>        // to override the jta-data-source in persistence.xml
>        props.put("openjpa.Connection2DriverName", driver);
>        props.put("openjpa.Connection2URL", url);
>        props.put("openjpa.Connection2UserName", user);
>        props.put("openjpa.Connection2Password", password);
>
>        // create the schema
>        props.put("openjpa.jdbc.SynchronizeMappings",
> "buildSchema(ForeignKeys=false)");
>        EntityManagerFactory emf =
> Persistence.createEntityManagerFactory(persistenceUnit, props);
>        em = emf.createEntityManager();
>
> The trick is you have to set both the Connection* and the Connection2*
> properties. Don't ask me why, though...
>
> Tested with OpenJPA 2.0.0.
>
> Regards,
> Harald
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Override-jta-data-source-with-system-properties-tp4173119p5312588.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message