Hi All
I have 2 million records in my table. I am using Oracle 10g as database, Spring 2.5.5 as application and hibernate 3.2 .
My query is taking about 22 seconds when I use hibernate, however when I use the query in SQL developer it takes only 1-2 seconds. My table is indexed by "dbField1" and is using CONTEXT index. This is quite urgent for me any help will be appreciated.
My hibernate mapping file is as below
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 2, 2009 5:35:45 PM by Hibernate Tools 3.2.4.CR1 -->
<hibernate-mapping>
<class name="MyClass" table="My_Table">
<id name="myTableId" type="string" unsaved-value="version">
<column name="My_TABLE_ID" length="20" />
<generator class="assigned" />
</id>
<version name="version" />
<property name="field1" type="string">
<column name="dbField1" length="12" />
</property>
<property name="field2" type="string">
<column name="dbField2" length="25" />
</property>
<property name="field3" type="string">
<column name="dbField3" length="25" />
</property>
<property name="field4" type="string">
<column name="dbField4" length="25" />
</property>
<property name="field5" type="string">
<column name="dbField5" length="3" />
</property>
<property name="field6" type="string">
<column name="dbField6" length="40" />
</property>
<property name="field7" type="string">
<column name="dbField7" length="2" />
</property>
<property name="field8" type="string">
<column name="dbField8" length="2" />
</property>
</class>
<resultset name="rsMyResultSet">
<return alias="rsMyResultSet" class="MyClass" />
</resultset>
<sql-query name="myQuery" resultset-ref="rsMyResultSet">
<![CDATA[
SELECT * FROM
My_Table WHERE
(:field1 IS NULL OR ( CONTAINS (dbField1, :field1, 1) > 0 AND ( ( :field8 = 'N' AND translate(substr(dbField1,-1),'0123456789',' ')!=' ') OR ( :field8 ='Y') )) )
AND ( :field2 IS NULL OR Upper (dbField2) LIKE Upper (:field2 ))
AND ( :field3 IS NULL OR Upper (dbField3) LIKE Upper (:field3 ))
AND ( :field4 IS NULL OR Upper (dbField4) LIKE Upper (:field4 ))
AND (:field5 IS NULL OR Upper (dbField5) = Upper (:field5 ))
AND ( :field6 IS NULL OR Upper (dbField6) LIKE Upper (:field6 ))
AND ( :field7 IS NULL OR Upper (dbField7) = Upper (:field7 )))
]]>
</sql-query>
</hibernate-mapping>
[/code]
My DAO object is as below:
Code:
Session sess = this.getSession();
sess.clear();
Query query =
sess.getNamedQuery("myQuery");
// SQLQuery query = getSession().createSQLQuery(qryNamed.getQueryString()).addEntity(MyClass.class);
query.setMaxResults(100);
query.setParameter("field1", getWildCardEnabledValue(myClass.getField1()));
query.setParameter("field2", getWildCardEnabledValue(myClass.getField2()));
query.setParameter("field3", getWildCardEnabledValue(myClass.getField3()));
query.setParameter("field4", getWildCardEnabledValue(myClass.getField4()));
query.setParameter("field5", getWildCardEnabledValue(myClass.getField5()));
query.setParameter("field6", getWildCardEnabledValue(myClass.getField6()));
query.setParameter("field7", getWildCardEnabledValue(myClass.getField7()));
query.setParameter("field8", myClass.isSearchAll() ? "Y" : "N");
System.out.println(" Query --->" + query);
System.out.println(" Start time --->" + new Date());
List<MyClass> l = (List<MyClass>) query.list();
System.out.println(" end time --->" + new Date());
return l;