-->
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.  [ 2 posts ] 
Author Message
 Post subject: Please help with this simple thing
PostPosted: Fri May 07, 2004 12:04 am 
Newbie

Joined: Thu May 06, 2004 11:31 pm
Posts: 2
Hi all,

I'm new to Hibernate. I've read (almost) all the documentation and spent hours reading the forum.
My application is a Java standalone one, which will be the base for a batch process.
It runs on AIX and DB2 8.1.
Here's the code:

try {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
tx = session.beginTransaction();
query2 = session.createQuery("from VbsSale as s where s.orderNo = '1234' and mach_type = ?");
query2.setCacheable(true);

for(int j=0; j < 1000; j++) {
System.out.println("#"+j);
query2.setParameter(0, ""+j);
query2.list();
}

query1 = session.createQuery("from BpSp2Fd as f where f.status='N'");
list = query1.list();
for( int i = 0; i<10; i++) {
sp2 = (BpSp2Fd) list.get(i);
ts = (Timestamp)sp2.getFeedKey();
System.out.println ("Processing FEED_KEY: " + ts.toString() + "," + total);
query2.setParameter(0, ""+total%1000);
query2.list();
}
tx.commit();
session.close();
}
catch (Exception e) {
.......
}



The problem is that query2 executes 500 times per second in the first "for" loop, but inside the other loop it executes 1 time per second.
It never returns a row since I hardcoded one of the values (order_no).
Without executing query2 in the second loop, the loop iterates 18,000 times in 50 seconds, if I add query2 it takes 3 hours.
Both query1 and query2 use database indexes. Query1 return 18,000 rows but in the example I only iterate through 10 of them.
Since there are no 1-many or anything like that, mapping files are very simple so I decided not to flood the forum with it.

Why does query2 executes in a different way inside the loop and outside it? Any suggestions please?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 10:55 pm 
Newbie

Joined: Thu May 06, 2004 11:31 pm
Posts: 2
I found the problem.

I needed to add Session.setFlushMode(FlushMode.COMMIT), since the AUTO value tries to synchronize the cache with the DB just too often.

Thanks to all the ones who tried to think about a solution!


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

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.