Hi All,
I am using Hibernate to migrate data from DB2(8.1) database to Oracle10g. I have a simple scenario where there is a foreign key association between 2 tables.
migrateObject - which helps in migrating process:
private void migrateObject(String entity) {
Transaction trans = null;
Session oracleSession = null;
Session DB2Session = null;
try {
DB2Session = DB2Factory.getSessionFactory().openSession();
oracleSession = OracleFactory.getSessionFactory().openSession();
trans = oracleSession.beginTransaction();
ScrollableResults query = DB2Session.createCriteria(entity).scroll(ScrollMode.FORWARD_ONLY);
int count = 0;
while(query.next()){
ProfitCenter pCenter = (ProfitCenter)query.get(0);
System.out.println("Firm UID: " + pCenter.getFirm().getFirmUID());
oracleSession.save(pCenter);
if(++count % 20 == 0) {
oracleSession.flush();
DB2Session.flush();
oracleSession.clear();
DB2Session.clear();
}
}
trans.commit();
oracleSession.close();
DB2Session.close();
}catch(Exception e) {
System.out.println("Exception occured while scrolling..." + e);
if(trans!= null)
trans.rollback();
if(oracleSession!= null)
oracleSession.close();
if(DB2Session!= null)
DB2Session.close();
}
}
where i/p entity is class name like "Firm" "Currency" etc.
DB2Session - session for Db2 and oracleSession - session for Oracle.
My Mapping file tags for db2 and oracle are:
db2 (ProfitCenter-db2.hbm.xml)
----
<many-to-one name="firm" column="GPFM01FK_FIRM_UID" class="Firm"/>
where profit center table has foreign key as FirmUID (primary key of Firm table)
oracle (ProfitCenter-ora.hbm.xml)
---
<many-to-one name="firm" column="GPFM01FK_FIRM_UID" class="Firm" />
the schema name is diff for db2 and oracle and thus need to maintain 2 diff mapping files.
My Java Class:
-------
public class ProfitCenter {
private Firm firm;
}
when I run this I am able to see the value fetched from DB2, But while inserting into oracle it throws org.hibernate.exception.SQLGrammarException:Couldnt execute JDBC batch update.
I am very new to Hibernate, Plz help me if I am doing something wrong.
Thanks
|