I'd guess this is the exception you're seeing:
 <openjpa-2.0.0-r422266:935683 fatal store error>
org.apache.openjpa.persistence.RollbackException: Unable to obtain a
TransactionManager using null.
 If that's the case you probably have some fields which use Table generation
(@GeneratedValue defaults to GenerationType.TABLE). In order to obtain the
next generated value OpenJPA uses the non-jta-data-source (or
ConnectionFactory2 / Connection2URL, etc.).

Regards,
-mike


On Mon, Jul 19, 2010 at 1:03 PM, Michael Dick <[email protected]>wrote:

> 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 <
> [email protected]> 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.
>>
>
>

Reply via email to