I'm seeing what I think is odd behavior when attempting to do a query by example. The example object has two fields populated, a user id field and an account status field. When I do the search I see two things.
1. As shown below, the user ID field isn't being used in the where clause of the select (though I have verified that it is populated).
2. No search results are being returned even though there are numerous records that meet the given criteria (i.e. even though it's just using the status flag in the where clause it should still be returning some results).
Can anyone suggest where I can start looking to fix these two issues or tell me what I'm not understanding about the query by example functionality?
Hibernate version:
2.1.6
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="x.x.x.model.sysadmin.UserVO"
table="ICIS_USER"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="USER_ID"
type="java.lang.String"
>
<generator class="assigned">
</generator>
</id>
<property
name="active"
type="x.x.x.common.server.dao.hibernate.ActiveInactiveType"
update="true"
insert="true"
access="property"
column="STATUS_FLAG"
/>
<property
name="dataAcessLevel"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="DATA_ACCESS_LEVEL_CODE"
/>
<property
name="dataAccessRegion"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="REGION_CODE"
/>
<property
name="sensitiveDataAccess"
type="x.x.x.common.server.dao.hibernate.ActiveInactiveType"
update="true"
insert="true"
access="property"
column="SENSITIVE_DATA_FLAG"
/>
<property
name="dataAccessState"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="STATE_CODE"
/>
<many-to-one
name="person"
class="x.x.x.model.sysadmin.PersonVO"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="PERSON_ID"
/>
<set
name="roles"
table="XREF_USER_ROLE"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="USER_ID"
>
</key>
<many-to-many
class="x.x.x.model.sysadmin.RoleVO"
column="ROLE_ID"
outer-join="auto"
/>
</set>
</class>
<query name="sysadmin.getUserByID"><![CDATA[
from UserVO user where user.id = :id
]]></query>
</hibernate-mapping>
Full package names have obsecured to for client confidentiality reason.
Code between sessionFactory.openSession() and session.close():Code:
Session session = HibernateSessionManager.getSession();
try
{
HibernateSessionManager.beginTransaction();
LoggingUtil.log("Preparing search by criteria");
Criteria searchCriteria = session.createCriteria(p_criteria);
if (p_exampleModel != null)
{
LoggingUtil.log("Addings example to criteria");
Example exampleModel = Example.create(p_exampleModel);
exampleModel.excludeZeroes();
exampleModel.ignoreCase();
exampleModel.enableLike(MatchMode.ANYWHERE);
searchCriteria.add(exampleModel);
}
if (p_fetchingStrategies != null)
{
Iterator itr = p_fetchingStrategies.keySet().iterator();
String association;
FetchMode mode;
while (itr.hasNext())
{
association = (String) itr.next();
mode = (FetchMode) p_fetchingStrategies.get(association);
LoggingUtil.log("Setting fetch mode for association "
+ association + " to " + mode);
searchCriteria.setFetchMode(association, mode);
}
}
if (p_criterions != null)
{
Iterator criterionItr = p_criterions.iterator();
Criterion criterion;
while (criterionItr.hasNext())
{
criterion = (Criterion) criterionItr.next();
searchCriteria.add(criterion);
}
}
List searchResults = null;
LoggingUtil.log("Performing search with the following criteria:\n"
+ searchCriteria.toString());
searchResults = searchCriteria.list();
return searchResults;
}
catch (HibernateException e)
{
LoggingUtil.log("Error performing search", e);
throw new ICISDBException(HibernateExceptionHelper
.getErrorCodeFor(e), e);
}
The session close appears when the results are returned to our web tier.
Full stack trace of any exception that occurs:N/A
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):Code:
Hibernate: select this.USER_ID as USER_ID4_, this.STATUS_FLAG as STATUS_F2_4_, this.DATA_ACCESS_LEVEL_CODE as DATA_ACC3_4_, this.REGION_CODE
as REGION_C4_4_, this.SENSITIVE_DATA_FLAG as SENSITIV5_4_, this.STATE_CODE as STATE_CODE4_, this.PERSON_ID as PERSON_ID4_, personvo1_.PERSO
N_ID as PERSON_ID0_, personvo1_.FIRST_NAME as FIRST_NAME0_, personvo1_.LAST_NAME as LAST_NAME0_, personvo1_.MIDDLE_NAME as MIDDLE_N4_0_, per
sonvo1_.TITLE as TITLE0_, personvo1_.MAIL_CODE as MAIL_CODE0_, personvo1_.ORGANIZATION_ID as ORGANIZA7_0_, personvo1_.OFFICE_ID as OFFICE_ID
0_, personvo1_.CERTIFICATION_TYPE_CODE as CERTIFIC9_0_, officephon2_.PERSON_PHONE_ID as PERSON_P1_1_, officephon2_.TELEPHONE_NMBR as TELEPHO
N3_1_, officephon2_.TELEPHONE_EXTENSION_NMBR as TELEPHON4_1_, officephon2_.PHONE_TYPE_CODE as PHONE_TY2_1_, officephon2_.PERSON_ID as PERSON
_ID1_, faxphone3_.PERSON_PHONE_ID as PERSON_P1_2_, faxphone3_.TELEPHONE_NMBR as TELEPHON3_2_, faxphone3_.TELEPHONE_EXTENSION_NMBR as TELEPHO
N4_2_, faxphone3_.PHONE_TYPE_CODE as PHONE_TY2_2_, faxphone3_.PERSON_ID as PERSON_ID2_, emailaddre4_.PERSON_ELECTRONIC_ADDRESS_ID as PERSON_
E1_3_, emailaddre4_.ELECTRONIC_ADDRESS_TEXT as ELECTRON3_3_, emailaddre4_.PERSON_ID as PERSON_ID3_, emailaddre4_.ELECTRONIC_ADDRESS_TYPE_COD
E as ELECTRON2_3_ from ICIS_USER this left outer join ICIS_PERSON personvo1_ on this.PERSON_ID=personvo1_.PERSON_ID left outer join NPDES_DE
V.ICIS_PERSON_PHONE officephon2_ on personvo1_.PERSON_ID=officephon2_.PERSON_PHONE_ID left outer join NPDES_DEV.ICIS_PERSON_PHONE faxphone3_
on personvo1_.PERSON_ID=faxphone3_.PERSON_PHONE_ID left outer join ICIS_PERSON_ELECTRONIC_ADDRESS emailaddre4_ on personvo1_.PERSON_ID=emai
laddre4_.PERSON_ELECTRONIC_ADDRESS_ID where (this.STATUS_FLAG=?)
Debug level Hibernate log excerpt:
N/A