-->
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.  [ 3 posts ] 
Author Message
 Post subject: PreparedStatement in Hibernate
PostPosted: Thu Apr 13, 2006 8:16 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 7:07 pm
Posts: 21
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate Version: 3.0.5

Hibernate Config:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">INGCoreConnection</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<property name="jndi.class">com.ibm.websphere.naming.WsnInitialContextFactory</property>
<!-- property name="hibernate.jdbc.use_get_generated_keys">true</property -->

<!-- property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property -->
<mapping resource="cl/ing/coreafp/pension/necessarycapital/properties/MortalityBean.hbm.xml" />
</session-factory>
</hibernate-configuration>
Mapping Information:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="cl.ing.coreafp.pension.necessarycapital.beans.MortalityBean" table="T_MORTALITYDATA"><!-- dynamic-update="true" -->

<id name="id" type="int" column="MD_SUR_ID" unsaved-value="null" />

<property name="year" type="int" column="MD_YEAR_PE" not-null="true" length="6"></property>
<property name="age" type="int" column="MD_AGE_NN" not-null="true" length="3"></property>
<property name="numberOfPersonsAlive" type="double" column="MD_NOOFPRSNSALIVE_NN" not-null="false" length="11"></property>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
if(session==null || !session.isConnected()){
session = HibernateSessionFactory.currentSession();
qy = session.createQuery("from MortalityBean objMortalityBean where objMortalityBean.year = :year and objMortalityBean.age= :age");

MortalityBean objMortalityBean = (MortalityBean)qy.setInteger("year",objMortalityBeanPK.getYear())
.setInteger("age",objMortalityBeanPK.getAge()).uniqueResult();
}
Console Information:
[4/13/06 17:36:16:203 IST] 0000002c Environment I hibernate.properties not found
[4/13/06 17:36:16:219 IST] 0000002c Environment I using CGLIB reflection optimizer
[4/13/06 17:36:16:234 IST] 0000002c Environment I using JDK 1.4 java.sql.Timestamp handling
[4/13/06 17:36:16:733 IST] 0000002c Configuration I configuring from resource: /cl/ing/coreafp/common/utilities/hibernate.cfg.xml
[4/13/06 17:36:16:749 IST] 0000002c Configuration I Configuration resource: /cl/ing/coreafp/common/utilities/hibernate.cfg.xml
[4/13/06 17:36:19:133 IST] 0000002c Configuration I Mapping resource: cl/ing/coreafp/pension/necessarycapital/properties/MortalityBean.hbm.xml
[4/13/06 17:36:19:164 IST] 0000002c HbmBinder I Mapping class: cl.ing.coreafp.pension.necessarycapital.beans.MortalityBean -> T_MORTALITYDATA
[4/13/06 17:36:19:164 IST] 0000002c Configuration I Configured SessionFactory: null
[4/13/06 17:36:19:164 IST] 0000002c Configuration I processing extends queue
[4/13/06 17:36:19:211 IST] 0000002c Configuration I processing collection mappings
[4/13/06 17:36:19:211 IST] 0000002c Configuration I processing association property references
[4/13/06 17:36:19:227 IST] 0000002c Configuration I processing foreign key constraints
[4/13/06 17:36:19:336 IST] 0000002c NamingHelper I JNDI InitialContext properties:{java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory}
[4/13/06 17:36:19:647 IST] 0000002c ConnectionFac W J2CA0294W: Deprecated usage of direct JNDI lookup of resource INGCoreConnection. The following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

[4/13/06 17:36:19:772 IST] 0000002c DatasourceCon I Using datasource: INGCoreConnection
[4/13/06 17:36:20:583 IST] 0000002c WSRdbDataSour I DSRA8203I: Database product name : Oracle
[4/13/06 17:36:20:598 IST] 0000002c WSRdbDataSour I DSRA8204I: Database product version : Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
[4/13/06 17:36:20:614 IST] 0000002c WSRdbDataSour I DSRA8205I: JDBC driver name : Oracle JDBC driver
[4/13/06 17:36:20:614 IST] 0000002c WSRdbDataSour I DSRA8206I: JDBC driver version : 9.2.0.1.0
[4/13/06 17:36:20:692 IST] 0000002c WSRdbDataSour I DSRA8208I: JDBC driver type : ""
[4/13/06 17:36:21:081 IST] 0000002c SettingsFacto I RDBMS: Oracle, version: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
[4/13/06 17:36:21:081 IST] 0000002c SettingsFacto I JDBC driver: Oracle JDBC driver, version: 9.2.0.1.0
[4/13/06 17:36:21:346 IST] 0000002c Dialect I Using dialect: org.hibernate.dialect.Oracle9Dialect
[4/13/06 17:36:21:378 IST] 0000002c TransactionFa I Transaction strategy: org.hibernate.transaction.CMTTransactionFactory
[4/13/06 17:36:21:424 IST] 0000002c TransactionMa I instantiating TransactionManagerLookup: org.hibernate.transaction.WebSphereExtendedJTATransactionLookup
[4/13/06 17:36:21:440 IST] 0000002c TransactionMa I instantiated TransactionManagerLookup
[4/13/06 17:36:21:440 IST] 0000002c SettingsFacto I Automatic flush during beforeCompletion(): enabled
[4/13/06 17:36:21:455 IST] 0000002c SettingsFacto I Automatic session close at end of transaction: enabled
[4/13/06 17:36:21:502 IST] 0000002c SettingsFacto I JDBC batch size: 15
[4/13/06 17:36:21:518 IST] 0000002c SettingsFacto I JDBC batch updates for versioned data: disabled
[4/13/06 17:36:21:518 IST] 0000002c SettingsFacto I Scrollable result sets: enabled
[4/13/06 17:36:21:565 IST] 0000002c SettingsFacto I JDBC3 getGeneratedKeys(): disabled
[4/13/06 17:36:21:580 IST] 0000002c SettingsFacto I Connection release mode: null
[4/13/06 17:36:21:580 IST] 0000002c SettingsFacto I Default batch fetch size: 1
[4/13/06 17:36:21:596 IST] 0000002c SettingsFacto I Generate SQL with comments: disabled
[4/13/06 17:36:21:611 IST] 0000002c SettingsFacto I Order SQL updates by primary key: disabled
[4/13/06 17:36:21:627 IST] 0000002c SettingsFacto I Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[4/13/06 17:36:21:642 IST] 0000002c ASTQueryTrans I Using ASTQueryTranslatorFactory
[4/13/06 17:36:21:674 IST] 0000002c SettingsFacto I Query language substitutions: {}
[4/13/06 17:36:21:689 IST] 0000002c SettingsFacto I Second-level cache: enabled
[4/13/06 17:36:21:689 IST] 0000002c SettingsFacto I Query cache: disabled
[4/13/06 17:36:21:689 IST] 0000002c SettingsFacto I Cache provider: org.hibernate.cache.EhCacheProvider
[4/13/06 17:36:21:752 IST] 0000002c SettingsFacto I Optimize cache for minimal puts: disabled
[4/13/06 17:36:21:752 IST] 0000002c SettingsFacto I Structured second-level cache entries: enabled
[4/13/06 17:36:21:783 IST] 0000002c SettingsFacto I Echoing all SQL to stdout
[4/13/06 17:36:21:830 IST] 0000002c SettingsFacto I Statistics: enabled
[4/13/06 17:36:21:830 IST] 0000002c SettingsFacto I Deleted entity synthetic identifier rollback: disabled
[4/13/06 17:36:21:845 IST] 0000002c SettingsFacto I Default entity-mode: pojo
[4/13/06 17:36:22:188 IST] 0000002c SessionFactor I building session factory
[4/13/06 17:36:22:235 IST] 0000002c Configurator W No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: wsjar:file:/C:/IWorkSpace/INGAFPCorePOC/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[4/13/06 17:36:25:103 IST] 0000002c SessionFactor I Not binding factory to JNDI, no JNDI name configured
[4/13/06 17:36:25:118 IST] 0000002c SessionFactor I Checking 0 named queries
[4/13/06 17:36:25:274 IST] 0000002c NamingHelper I JNDI InitialContext properties:{java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory}
[4/13/06 17:36:25:321 IST] 0000002c SystemOut O in dao of contracts module
[4/13/06 17:36:25:321 IST] 0000002c SystemOut O Affiliate RUT is 22222222
[4/13/06 17:36:25:399 IST] 0000002c ConnectionFac W J2CA0294W: Deprecated usage of direct JNDI lookup of resource INGCoreConnection. The following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)


Oracle 9.2:

The generated SQL (show_sql=true):
select mortalityb0_.MD_SUR_ID as MD1_, mortalityb0_.MD_YEAR_PE as MD2_13_,

mortalityb0_.MD_AGE_NN as MD3_13_, mortalityb0_.MD_NOOFPRSNSALIVE_NN as MD4_13_ from T_MORTALITYDATA mortalityb0_ where

mortalityb0_.MD_YEAR_PE=? and mortalityb0_.MD_AGE_NN=?



When looked up for, say, 5000 times, the query is parsed every time (Oracle trace revealed that).
The keys age, year vary. The table has a Composite unique index on age, year

The keys vary on every call and hence this is an ideal case to use JDBC Preparedstatement. When the application uses Java Preparedstatement,

the result is obtained in less than 3 secs. However, when using Hibernate, this runs for several minutes - sometimes times out.

Could someone help me understand how to use Preparedstatemnt effectively in Hibernate?

_________________
Today is the Tomorrow that you were worried about Yesterday.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 10:35 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hibernate needs a connection pool for prepared statement pooling.
If you use C3P0 for that, everything works fine.
It looks like you are using websphere, so the problem may be
in your websphere connection pool.

Hope this helps.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 8:29 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 7:07 pm
Posts: 21
Thanks for responding, Steckemetz. Could you please tell where and what to configure in Websphere Connection pool to get rid of this problem? Websphere Version 6

_________________
Today is the Tomorrow that you were worried about Yesterday.


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