I am trying to optimize database queries in Hibernate, but I found a blocker:
<class name="SupportedLanguageVO" table="AR_SUPPORTED_LANG" >
<cache usage="read-only"/>
<id name="Id" type="java.math.BigInteger">
<column name="ID" sql-type="NUMBER(20)" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="OrderSeq" type="java.math.BigInteger">
<column name="ORDER_SEQ" sql-type="NUMBER(20)" not-null="true"/>
</property>
<many-to-one name="Country" class="CountryVO" column="CTRY_CD_ID" cascade="none" >
<many-to-one name="Language" class="LanguageVO" column="LANG_CD" cascade="none" >
</class>
The primary key of the country is CTRY_CD_ID
. If I fulfill the following criteria
Criteria crit = m_Session.createCriteria(SupportedLanguageVO.class);
crit.createCriteria("Country").add(Restrictions.eq("_CountryCode", p_countrycode));
crit.addOrder(Order.asc("OrderSeq"));
I see hibernation joining the ctry and AR_SUPPORTED_LANG tables. What for? It would be better to run
select * from AR_SUPPORTED_LANG where ctry_cd_id=?
sql instead
select * from AR_SUPPORTED_LANG inner join ctry .... where ctry_cd_id=?
Is it possible to get hibernate to execute the first request?
source
share