-->
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.  [ 5 posts ] 
Author Message
 Post subject: reuse of prepared statements
PostPosted: Mon May 03, 2004 7:30 am 
Newbie

Joined: Thu Apr 08, 2004 7:17 am
Posts: 10
Hi,

Im porting a J2EE application from CMP/CMT to hibernate. We use the framework from http://www.cassar.id.au/hibernate-j2ee/ to integrate hibernate.

In some parts of our application we use finders the retreive the data from the database. In one transaction some finders are called many times with different parameter values. A classic example for prepared statements.

Now we have the problem, that hibernate is about 3-4 times slower than our application server (Orion). I looked at the hibernate code and did a little moving step by step to the code. The main performance killer is, that for every finder execution a NEW prepared statement is created!

Why do you use prepared statements if you dont reuse them or is this a configuration problem?

Thanks in advance, and please dont get me wrong. I like hibernate and I think it is the best persistence layer around.

Thanks.
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:39 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what connexion pooling are you using?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:51 am 
Newbie

Joined: Thu Apr 08, 2004 7:17 am
Posts: 10
I use the connection pooling of the orion application server.
I configured hibernate to get the connections from the JNDI context.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 8:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Prepared Statement pooling is the job of the pool, not of Hibernate. If your Orion Datasource does not do that, we can't do anything about it. c3po, dbcp and JBoss datasources for example can all be configured to do transparent prepared statement pooling, so we won't reimplement that inside of Hibernate again.


Top
 Profile  
 
 Post subject: Re: reuse of prepared statements
PostPosted: Thu Jun 17, 2010 9:45 am 
Newbie

Joined: Tue May 04, 2010 6:56 am
Posts: 2
Hi, I just read this thread because I have the same question and I'm not sure it was properly answered.

I tried reusing prepared statements by using C3P0. But what it does is caching java object instances of prepared statements while the actual prepared statement in the database is still opened and closed instead of reused.

Here is an extract of the log when using C3P0's statement cache:

12:56:20,338 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
12:56:20,338 DEBUG AbstractBatcher:562 - closing statement
12:56:20,338 DEBUG GooGooStatementCache:271 - checkinStatement(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 1; checked out: 0; num connections: 1; num keys: 1

As you can see the prepared statement is closed before an instance is checked into the C3P0-Statementcache.

When the same statement is repeated another prepared statement is opened before the statement object is loaded out of the C3P0-Cache:

4:12:34,786 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
14:12:34,786 DEBUG AbstractBatcher:513 - preparing statement
14:12:34,786 DEBUG GooGooStatementCache:457 - cxnStmtMgr.statementSet( com.ibm.db2.jcc.c.b@9ba045 ).size(): 2
14:12:34,786 DEBUG GooGooStatementCache:196 - checkoutStatement: com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 2; checked out: 1; num connections: 1; num keys: 2

As you can see prepared statements are not reused by using the C3P0-Statement cache. Only some kind of java object instance is saved and loaded from the C3p0-Cache while the actual prepared statement is closed and reopened which is a performance killer in batch applications.

Am I missing something? Thx in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.