You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by is_maximum <mn...@gmail.com> on 2009/05/17 12:12:00 UTC

Re: persistence problem in distributed environment

Hi

According to OpenJPA manual:

Certain application servers automatically enlist their DataSource s in
global transactions. When this is the case, OpenJPA
should not attempt to commit the underlying connection, leaving JDBC
transaction completion to the application server. To notify
OpenJPA that your third-party DataSource is managed by the application
server, use the jta-data-source element of
your persistence.xml file or set the openjpa.ConnectionFactoryMode property
to managed.
Note that OpenJPA can only use managed DataSources when it is also
integrating with the application server's managed transactions.
Also note that all XA DataSources are enlisted, and you must set this
property when using any XA DataSource.
When using a managed DataSource, you should also configure a second
unmanaged DataSource that OpenJPA can use to
perform tasks that are independent of the global transaction. The most
common of these tasks is updating the sequence table
OpenJPA uses to generate unique primary key values for your datastore
identity objects. Configure the second DataSource using
the non-jta-data-source persistence.xml element, or OpenJPA's various "2"
connection properties, such as
openjpa.ConnectionFactory2Name or openjpa.Connection2DriverName.


but unfortunately this doesn't work at all and the problem still exists and
we have to set the other side of the relationship with getReference() method
at the time we are going to persist the entity.

Any idea?

Paul Copeland wrote:
> 
> Does the test below fail for you?  It works correctly for Ravi.  Can you 
> send an example that demonstrates the problem?
> 
> On 4/13/2009 8:08 AM, hmmahboobi wrote:
>> Hi
>>
>> Thanks for your response,
>>
>> This model is a small view of our large system,
>> Actual codes are very large and complex, so I cant send entire model for
>> you.
>> Is there any considrations that help me to solve this problem?
>>
>>
>> Hi,
>>
>> I am unable to replicate the issue. The sample code you mentioned in
>> problem description is working as expected on weblogic application server
>> with oracle database (10.1.0.2) and oracle XA driver ("Oracle JDBC Driver
>> version - 10.1.0.2.0").
>>
>> Here is the configuration I used: 
>>
>> persistence.xml 
>> oracleXADataSource.xml 
>> Source code 
>>
>> SQL> select * from voucher;
>>
>>         ID ACCOUNT_ID
>> ---------- ----------
>>        123        215
>>        120        215
>>        130        215
>>
>> If you think my test case is not in sync with your explanation then
>> please upload a replicable test case.
>>
>> Regards,
>> Ravi.
>>
>>
>>
>> We have a critical problem in our application, we have multiple
>> enterprise applications and we have to use distributed transactions to
>> ensure ACID operations on entire system.
>> Our Application server is Glassfish V9 update 5 on SUSE 10 and database
>> is Oracle 10.2.0.1.0.
>> The problem is when we use oracle.jdbc.xa.client.OracleXADataSource as
>> JDBC driver and javax.sql.XADataSource as resource type, we get following
>> error in persisting an entity with a ManyToOne relationship and it
>> complains the other side of relationship is unmanaged!!! However the
>> other side of the relationship (here account entity) is already existed
>> in database and with typical JDBC driver, no error we encounter. I have
>> tested all other OpenJPA versions but the problem still exists. I don’t
>> know whether this is OpenJPA issue or JDBC driver, please share your
>> experience on this matter.
>>
>>
>> javax.ejb.TransactionRolledbackLocalException: Exception thrown from
>> bean; nested exception is: <openjpa-2.0.0-M1-SNAPSHOT-r422266:725770
>> fatal user error> org.apache.openjpa.persistence.InvalidStateException:
>> Encountered unmanaged object in persistent field
>> "com.kishware.core.gl.data.Voucher.account" during flush.  However, this
>> field does not allow cascade persist. Set the cascade attribute for this
>> field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or
>> "persist" or "all" (JPA orm.xml), or enable cascade-persist globally, or
>> manually persist the related field value prior to flushing. You cannot
>> flush unmanaged objects or graphs that have persistent associations to
>> unmanaged objects.
>> FailedObject:
>> com.kishware.core.gl.data.Account-com.kishware.core.gl.data.Account-215
>>
>>
>> This is our entity classes and simple test case:
>>
>> public class Voucher {
>> @Id
>>       @Column(name = "id")
>>       @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator =
>> "VoucherSequenceGenerator")
>> private Long id;
>>       
>> @ManyToOne
>> @JoinColumn(name = "account_id")
>>       private Account account;
>> }
>>
>> public class Account {
>> @Id
>>       @Column(name = "id")
>>       @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>> "AccountSequenceGenerator")
>>       private Long id;
>> }
>>
>> Account account = entityManager.find(Account.class, 215L);
>> Voucher voucher = new Voucher();
>> Voucher.setAccount(account);
>> entityManager.persist(voucher);
>>
>>
>>
>>
>>
>>
>>   
> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/persistence-problem-in-distributed-environment-tp2619875p2915723.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.