-->
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: Could not execute Batch Update (SQLGrammarException)
PostPosted: Fri Apr 18, 2008 2:53 pm 
Newbie

Joined: Thu Apr 17, 2008 6:28 pm
Posts: 6
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


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.