I am using Hibernate 3 with Oracle 9i.
I am running Batch Insert .The process is extremly slow.It is taking long time to insert data.
I Also added following properties in hibernate.cfg.xml file.
Code:
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
I there is something else I am missing.
Following is the code I am using for batch Inserts.
Code:
public class OTISTestLoading {
private static SessionFactory sessionFactory;
static {
sessionFactory = new Configuration().configure("/hibernate_oracle.cfg.xml").buildSessionFactory();
}
public static void main(String[] args) throws Exception {
final OTISloading app = new OTISloading();
System.out.println("###############################################");
Session session = null;
Transaction tx = null;
Otis o;
Patient p = null ;
Appointment a;
Entry entry1=null;
Queue queue=null;
Ews e=null;
Format formatter;
Integer status = new Integer(10);
Date startDate1=null;
String Organ="";
int recordId=0;
int episode=0;
try{
session = sessionFactory.openSession();
tx = session.beginTransaction();
Query q3 = session.createQuery(
"from Patient p "
);
List qlist3 = q3.list();
for (int i = 0; i < qlist3.size(); i++ ) {
p = (Patient)qlist3.get(i);
String name1= p.getName();
String cpi =p.getCpiNumber();
String rule1 ="rule" + i;
String type1 ="type" + i;
String name2 ="name" + i;
if (p.getEntry()== null ) {
queue = new Queue("rule1","type1","name1");
session.save(queue);
Query q4 = session.createQuery(
"from Otis o where o.regNumber =:nbr AND ROWNUM=1 "
);
q4.setParameter("nbr", cpi);
List qlist4 = q4.list();
if(qlist4.size() >0){
Otis otis = (Otis)q4.list().get(0);
startDate1 =otis.getStartDate();
Organ=otis.getOrgan();
recordId=otis.getRecordId();
episode=otis.getEpisode();
}
else{
startDate1=null;
Organ=null;
recordId=0;
episode=0;
}
entry1 = new Entry(p, status,startDate1,queue,Organ,recordId,episode);
session.save(entry1);
History history = new History("OTIS", new Date(), null, null, "created entry", entry1);
entry1.addHistory(history);
}
for (Iterator it = p.getAppointments().iterator(); it.hasNext(); ) {
Appointment appt = (Appointment)it.next();
// Create TBW Task if no task for this appointment and appointment date is later than begin date
Query q1 = session.createQuery(
"select o.startDate,o.eventType,o.endDate,o.recordId,o.episode from Otis o where o.regNumber =:nbr "
);
q1.setParameter("nbr", cpi);
List qlist1 = q1.list();
for (int j = 0; j < qlist1.size(); j++ ) {
Object[] obj1 = (Object[])qlist1.get(j);
Date startDate =(Date) obj1[0];
String eventType = obj1[1].toString();
Date endDate =(Date) obj1[2];
if(eventType.trim().equals("Eval")){
if((startDate !=null && endDate ==null && appt.getAppointmentDate().after(startDate))|| (startDate!=null && endDate !=null && appt.getAppointmentDate().after(startDate) && appt.getAppointmentDate().before(endDate))){
Task task = new Task(appt, status, null, entry1);
appt.setTask(task);
entry1.addTask(task);
}
}
if(eventType.trim().equals("List")){
if((startDate !=null && endDate ==null && appt.getAppointmentDate().after(startDate))|| (startDate!=null && endDate !=null && appt.getAppointmentDate().after(startDate) && appt.getAppointmentDate().before(endDate))){
Task task = new Task(appt, status, null, entry1);
appt.setTask(task);
entry1.addTask(task);
}
}
}
if(i %20 ==0){
session.flush();
session.clear();
}
}
}
tx.commit();
session.close();
}
catch (Exception exp) {
if (tx!=null) {
try {
tx.rollback();
exp.printStackTrace();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
finally {
try {
session.close();
}
catch (Exception ex ){
ex.printStackTrace();
}
}
// Work with the loading data
// Close the SessionFactory
sessionFactory.close();
}
}
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: