openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ognjen Blagojevic <ogn...@etf.bg.ac.yu>
Subject Re: Synchronizing two databases with the same model
Date Mon, 05 May 2008 08:56:01 GMT
I agree. I also need to fallback to native SQL when migrating data, just 
because we would like to preserve primary keys.

Regards,
Ognjen


Andy Schlaikjer wrote:
> Jonas,
> 
> I'm glad you asked this question as I'd also been thinking about how I 
> might get around restrictions the @GeneratedValue annotation enforces 
> within OpenJPA.
> 
> In certain circumstances I need to specify the value of a field marked 
> with @GeneratedValue explicitly when persisting a new entity instance. 
> I'd hoped that perhaps "merge" semantics would differ from "persist" 
> semantics with respect to this constraint, but it seems (quite 
> logically) that the constraint is applied uniformly to all entity 
> life-cycle operations.
> 
> For the time being I've had to fall back on JDBC to persist new data, 
> but it'd be great if there were a way to signal to OpenJPA that a field 
> marked with GeneratedValue may be explicitly defined for certain 
> operations, like merge or persist.
> 
> Andy
> 
> Jonas Petersen wrote:
>> Hi Brill,
>>
>> thanks for replying. The thing is, that only certain parts (e.g. an 
>> entity with certain id including child objects) have to get 
>> synchronized at the time by demand of a content editor.
>>
>> The datastore is mysql 5.
>>
>> Jonas
>>
>> Brill Pappin schrieb:
>>> Actually, the most obvious approach is not to write some special 
>>> code, but
>>> simply enable replication and don't worry about trying to get OJPA to 
>>> sync.
>>> What kind of database is it (most popular db's have replication of 
>>> one sort
>>> or another)?
>>>
>>> - Brill Pappin
>>>
>>> -----Original Message-----
>>> From: Jonas Petersen [mailto:jonas@mindfloaters.de] Sent: Wednesday, 
>>> April 30, 2008 3:25 PM
>>> To: users@openjpa.apache.org
>>> Subject: Synchronizing two databases with the same model
>>>
>>> Hi there!
>>>
>>> We have one data model and we need two datastores with that same data 
>>> model.
>>> Datastore A for editing and previewing and datastore B for production
>>> (live).
>>>
>>> Now we need to synchronize parts of datastore A to datastore B.
>>>
>>> The most obvious approach would be: fetch objects from datastore A (and
>>> possibly detach the objects) and then merge them in database B. But this
>>> rises a couple of problems due to versioning / sequence generators /
>>> optimistic locking / ...
>>>
>>> e.g.:
>>> - If objects (detached from datastore A) do not exist in datastore B, 
>>> they
>>> are assumed deleted and an exception is thrown
>>> - Since we're using the GeneratedValue annotation for ids, objects 
>>> would not
>>> be able to get persisted in datastore B even if they were new.
>>>
>>> Do you have any idea how to solve this problem in a regular way?
>>>
>>> One (non JPA-)way would be to implement it with  native queries. 
>>> Maybe this
>>> is the only way? Would probably be harder to maintain though.
>>>
>>> Thanks for any suggestion!
>>>
>>> Regards
>>> Jonas
>>>
>>>
>>>   
>>
>>
> 


Mime
View raw message