-->
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: poor performace, maybe missunderstood cache??
PostPosted: Fri Oct 22, 2004 6:42 am 
Newbie

Joined: Fri Oct 22, 2004 6:14 am
Posts: 1
Hibernate version: 2.1
Using Oracle 9
Code between sessionFactory.openSession() and session.close():


I'm new to Hibernate and am experiencing some strage performance problems. I can't find the answer in the FAQ or docs, so here goes...

My application is essentially listening to a data stream, creating objects out of that stream, and saving them to a db. The objects in question contain references to other objects and if these 'reference' objects don't exists in the db then they are created also (I'm basically creating reference data on the fly). So it looks somethine like this:



private Session session;

public void receiveMessage(String[] rawData) throws HibernateException, SQLException {
String name = rawData[0];
String companyName = rawData[1]; //this is reference data

List list = session.createQuery("from Company where name = ?")
.setParameter(0, companyName, Hibernate.STRING)
.setCacheable(true)
.list();

Company company;
if(list.size() == 0) {
company = new Company(name);
session.save(company);
} else {
company = (Company) list.get(0);
}

Person person = new Person(name, company);
session.save(person);
session.flush();
session.connection().commit();
}



In the mapping file for company I have enabled caching by adding <cache usage="read-write"/> and in hibernate.properties i have hibernate.cache.provider_class net.sf.hibernate.cache.EhCacheProvider.

The cache does seem to be working; once a company is in memory it never seems to re-select it from the db. However, the problem is that after running for a few hundred times, the code that selects the company is getting slower and slower. The real application has about eight bits of 'reference data' (like company), and when its first run it takes just a few milliseconds to get all the reference data required for the final insert, but after a few minutes it takes seconds.

Inserts to the ref data table rarely occur.

What was strange is when I added session.clear() after the commit everything worked very quickly.

So, I guess my question is - what am i doing wrong? Using the cache seems to have slowed my app down!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 6:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
use session./query/.iterate() if you are using second level cache

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.