Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!

Alfred Couder

+ Follow
since Jan 29, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alfred Couder

Rahul Babbar wrote:I bet you knew this was coming..but isn't it easier to just do it using Oracle utilities like Import and Export?

Indeed, I cannot say that you've surprised me here.

Thanks for answering Rahul.

Import/Export can as well imply off line database while 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 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"

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.

    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) 'SELECT Entity FROM TableX WHERE 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...?

    H all,

    this comes from the EJB3 in action book :

    Another drawback for BMT is the fact that it can never join an existing transaction.

    I would like to be sure I'm getting this right with your help if you do not mind too much.

    I want to have full control of any transaction which made me interested in BMT.

    Everything works and now I want to develop some more sophisticated code using BMT. However I would hate having methods of hundreds of line.
    Here What I would like to do : have a main service (let's call it MS) with a method opening a transaction, calling other methods services (let's call them s1, s2) and then commit.

    As long I only use methods of others services that only execute Data reading (find* methods), I'm fine.

    But If I want to have methods modifying data, I would get the sadly famous javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction.

    what I am trying to do looks like this :

    So far, the only way I have is to have the code of each method of each sub service inside my method from MS. that makes it super long which I find is ridiculous...

    any idea? how to do differently?
    Thanks to parmendratyagi (on

    This just does the job :

    Hibernate version: 3.0.5
    JBOSS Server: 4.3.0.GA
    Database: Oracle10G

    I am sorry to ask this question because it seems to me as some basics in SQL. Nonetheless I see nothing quite close to it in the books and web sites I am searching in.

    so easy in SQL, I thought it expected it to be easy with hibernate ate well.

    I have on table linked with many others. First, the DB schema is old and most of the table lacks primary keys (But embedded Id fixed that, thanks!)

    Now, all I want is to make two join between table.

    I basically have two table A and B. In each table, I have two common fields such as A.field1 = B.field3 and A.filed2 = B.filed4.

    this a one-to-many unidirectional relation from A to B : each record from A has many related records in B.

    I created an entity EA :

    and another EB :

    So how do I make my mapping so when I load an entity EA, I can have a list of all related EB? (meaning all EB respecting the joins A.field1 = B.field3 and A.filed2 = B.filed4)?