-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Avoiding merging with batch process between 2 databases ??!
PostPosted: Mon Mar 16, 2009 7:28 am 
Newbie

Joined: Fri Feb 06, 2009 2:16 am
Posts: 8
Hibernate 3.3.1.GA
JBOSS 4.3.0.GA
Oracle 10g, Driver ojdbc14.jar version 10.2.0.4.0

Hi,

I'm developing a batch process application requiring to transfer from one instance of Oracle to another instance of Oracle, respectively 'Prod' and 'Arch'.
so I need to
    - load entities from Prod
    - persist them in Arch
    - remove them from Prod
Basically my problem is how do I load one entity, persist it in one data source, remove it from another datasource WITHOUT MERGING?

With the biggest load of data to move :
    - selecting and copying the set of entities take 5 minutes
    - but merging and deleting takes 25 minutes.
I'm trying to have some archiving service/agent running in the background of applications.
Going full JDBC is also an option, and going down to stocked procedure would probably be the fastest way.

However, I rather try benefiting from object relational mapping in terms of reusable business object.
So, I want to believe that there is a way with JTA, Hibernate, to avoid the performance issue that I'm having with this merging step.

all in all, I haven't that many posts about dealing with multi base environment. It must have been considered and experimented before to manipulating important amount of data between two databases and more.

Please someone, say "yes"

In detail:
    JBOSS: 4.3.0.GA
    Hibernate : 3.3.1.GA
The total process involves :
    - 50 tables among which are tables with millions of rows
    - one entity per existing table
So I have
    - two XA datasources, one for each database, 'Prod' and 'Arch'.
    - two persistence Units.
    - two entity managers
    - 50 entity beans
    - 50 services, one for each entity
    - 1 main implementation in service
The process, step by step :
    - instantiating one entity manager for Prod : emProd
    - instantiating one entity manager for Arch: emArch
    - from Prod, selecting in the first table one record : emProd.findEntity()
    - returns one main entity ME1
    - from Prod, in the rest of the 49 tables, one select per table to match data linked to this ME1 : emProd.findEntity1LinkedtoME1()
    - returns collections of entities
    - persisting all those entities in Arch using : emArch.persist(<entity>)
    - because persisting detaches my entities I have to merge them : emProd.merge(<entity>)
    - before calling for deletion : emProd.remove()
And this has to be wrong somehow. it works but it looks insane. why? because what happens is that for each loaded entity, the merge will call a Select from respective database, ending up a huge lots of queries.
Meaning, what happes is :
    - selecting concerned entities = 50 SELECTs
    - copying to Archive = (number of entities) x INSERTs
    - merging each entity = (number of entities) x SELECT Entity FROM TableX WHERE PK = Entity.pk'
    - deleting = (number of entities) x DELETE

So, is there anyway to avoid the "merging" phase without coming down to use native queries to delete data using the entities still up to date, even if detached...?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.