Here are the Hibernate SQL statement logging:
For HQL query:
Code:
select patient0_.ID as ID16_, patient0_.FORENAME_1 as FORENAME2_16_, patient0_.FORENAME_2 as FORENAME3_16_, patient0_.SURNAME as SURNAME16_ from VW_PATIENTS patient0_ where (patient0_.FORENAME_1 like 'ste%') and (patient0_.SURNAME like 'mor%')
For Criteria:
Code:
select this_.ID as ID16_0_, this_.FORENAME_1 as FORENAME2_16_0_, this_.FORENAME_2 as FORENAME3_16_0_, this_.SURNAME as SURNAME16_0_ from VW_PATIENTS this_ where this_.FORENAME_1 like ? and this_.SURNAME like ?
As you can see, it produces exactly the same SQL query. So how Criteria could be slower than HQL?
Here is my hbm file for information:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.hhnt.common.domain.patient.Patient" table="TBL_PATIENTS">
<id name="id"
column="ID"
type="long" >
<generator class="assigned"/>
</id>
<property name="forename1"
column="FORENAME_1"
type="string"
length="35"
/>
<property name="forename2"
column="FORENAME_2"
type="string"
length="35"
/>
<property name="surname"
column="SURNAME"
type="string"
length="35"
/>
</class>
</hibernate-mapping>