Hi I try to optimize the 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 the CTRY_CD_ID
. If I run 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 can see, that hibernate joins the ctry and the AR_SUPPORTED_LANG tables. Why? It would be better to run
select * from AR_SUPPORTED_LANG where ctry_cd_id=?
sql rather than
select * from AR_SUPPORTED_LANG inner join ctry .... where ctry_cd_id=?
Can I force hibernate to run the first query?