openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ram.sankar" <ram.6...@gmail.com>
Subject Re: Issue in Handling persistent objects across multiple persistence contexts
Date Tue, 10 Mar 2009 04:57:37 GMT

Yes rick, i am using merge only, please have a look at the below code:

		writeEm.getTransaction().begin();
		om.detach(beanVar);
		DataObject bean = writeEm.merge(beanVar);
		writeEm.persist(bean);

writeEm = EntityManager for writing alone
om = entityManager for reading alone

Regards,
Ram


Rick Curtis wrote:
> 
> Ram -
> When you want to write your detached Entity back to the DB, are you using
> EntityManager.merge(..)? If not, I'd give that a try.
> 
> -Rick
> 
> Ram.sankar wrote:
>> 
>> Hi,
>> 
>> In my application i have a requirement that eventhough i change the
>> values of persistent objects available in the session directly using
>> getter and setter methods i have to save only the objects on which the 
>> EntityManager.persist() is invoked explicitly. To resolve this problem we
>> maintain 2 managers one for read and another for write. I detach the
>> object from the read entity manager and merge the same with the write
>> entity manager before calling a persist(). 
>> The problem here is that OpenJPA is generating an insert query to save
>> the persistent object eventhough it exists in the table. This is giving
>> me an Unique constraint violated error. Is there anyway to tell OpenJPA
>> to check for the existence of record with same primary key before
>> persisting. Any help is highly appreciated.
>> 
>> Regards,
>> Ram
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Issue-in-Handling-persistent-objects-across-multiple-persistence-contexts-tp2449327p2453321.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message