persistence@glassfish.java.net

Why is there no need to close a Query?

From: Markus Karg <karg_at_quipsy.de>
Date: Wed, 18 Jun 2008 16:23:49 +0200

I am using JDBC for a long time, and I have been using other DBMS APIs for far longer time. In almost any of those APIs I had the possibility to open a "Prepared Statement", that will get reused internally by the driver (no more need to parse the SQL again in a loop -- just the parameter values will get send to the DBMS). This is a good performance tuning thing when doing things in a loop, but one must take good care to close the statement when done -- otherwise one might run out of statement handles soon (e. g. in SQLAnywhere the admin can set a maximum limit of e. g. 10 open statements per connection to find defective applications not closing correctly the handles).

Now since a few months I am using JPA, and I am wondering why there is nothing like a Query.close() method. I am pretty sure that Oracle did it's best to improve performance, so I expect that a query actually internally is using a PreparedStatement instead of sending the same SQL string all the time. But how to handle the out-of-handles problem?

How does TopLink know that my admin is not allowing more than 10 open handles?

Or IS there some hidden Query.close() method that I just do not know?

Thanks!
Markus

QUIPSY QUALITY GmbH & Co. KG
Ein Unternehmen der MES-Gruppe
Stuttgarter Strasse 23
D-75179 Pforzheim
Tel: 07231-9189-52
Fax: 07231-9189-59
www.quipsy.de
karg_at_quipsy.de
Registergericht Mannheim HRA 701214
Geschäftsführer: Nils Schroeder

Diese E-Mail enthält persönliche, vertrauliche und vor Weitergabe geschützte Informationen und ist ausschließlich für den vorgesehenen o.g. Empfänger (Adressaten) bestimmt. Falls Sie diese E-Mail versehentlich erhalten haben und nicht der vorgesehene Empfänger sind, bitten wir Sie, die E-Mail und deren Anhänge nicht aufzubewahren, nicht zu vervielfältigen, nicht zu nutzen und nicht weiterzugeben. Bitte informieren Sie uns als Absender über diesen Zustellungsfehler und löschen Sie die E-Mail.