-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How do I exclude subclasses from a Query By Example?
PostPosted: Mon Jul 31, 2006 4:04 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
Hibernate version: 3.1.2

Mapping File: Resource.hbm.xml
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">
<hibernate-mapping>
    <class name="com.nkics.socialworkprn.swan.domain.Resource" table="RESOURCE">
        <id name="id" type="int">
            <column name="RESOURCE_ID" />
            <generator class="native" />
        </id>
        <one-to-one name="user" cascade="all"/>
        <many-to-one name="coordinator" class="com.nkics.socialworkprn.swan.domain.Coordinator" fetch="select">
            <column name="COORDINATOR_RESOURCE_ID" />
        </many-to-one>
        <many-to-one name="driversLicenseState" class="com.nkics.socialworkprn.swan.domain.State" fetch="select" lazy="false" cascade="persist,save-update,merge">
            <column name="RESOURCE_DRIVERS_LICENSE_STATE_ID" />
        </many-to-one>
        <many-to-one name="office" class="com.nkics.socialworkprn.swan.domain.Office" fetch="select" lazy="false" cascade="persist,save-update,merge">
            <column name="OFFICE_ID" not-null="true" />
        </many-to-one>
        <many-to-one name="resourceSource" class="com.nkics.socialworkprn.swan.domain.ResourceSource" fetch="select" lazy="false" cascade="persist,save-update,merge">
            <column name="RESOURCE_SOURCE_ID" />
        </many-to-one>
        <many-to-one name="state" class="com.nkics.socialworkprn.swan.domain.State" fetch="select" lazy="false" cascade="persist,save-update,merge">
            <column name="STATE_ID" />
        </many-to-one>
        <property name="firstName" type="string">
            <column name="RESOURCE_FIRST_NAME" length="40" not-null="true" />
        </property>
        <property name="middleName" type="string">
            <column name="RESOURCE_MIDDLE_NAME" length="40" />
        </property>
        <property name="lastName" type="string">
            <column name="RESOURCE_LAST_NAME" length="40" not-null="true" />
        </property>
        <property name="nickname" type="string">
            <column name="RESOURCE_NICKNAME" length="40" />
        </property>
        <property name="active" type="boolean">
            <column name="RESOURCE_ACTIVE" not-null="true" />
        </property>
        <property name="addressLine1" type="string">
            <column name="RESOURCE_ADDRESS_LINE1" length="40" />
        </property>
        <property name="addressLine2" type="string">
            <column name="RESOURCE_ADDRESS_LINE2" length="40" />
        </property>
        <property name="city" type="string">
            <column name="RESOURCE_ADDRESS_CITY" length="40" />
        </property>
        <property name="zip5" type="string">
            <column name="RESOURCE_ADDRESS_ZIP5" length="5" />
        </property>
        <property name="zip4" type="string">
            <column name="RESOURCE_ADDRESS_ZIP4" length="4" />
        </property>
        <property name="emergencyContactName" type="string">
            <column name="RESOURCE_EMERGENCY_CONTACT_NAME" length="128" />
        </property>
        <property name="emergencyContactPhone" type="string">
            <column name="RESOURCE_EMERGENCY_CONTACT_PHONE" length="10" />
        </property>
        <property name="email" type="string">
            <column name="RESOURCE_EMAIL" length="128" />
        </property>
        <property name="hoursPerWeek" type="integer">
            <column name="RESOURCE_HOURS_PER_WEEK" />
        </property>
        <property name="ssn" type="string">
            <column name="RESOURCE_SSN" length="9" />
        </property>
        <property name="birthdate" type="timestamp">
            <column name="RESOURCE_BIRTHDATE" length="23" />
        </property>
        <property name="male" type="boolean">
            <column name="RESOURCE_MALE" not-null="false" />
        </property>
        <property name="malpracticeInsuranceCo" type="string">
            <column name="RESOURCE_MALPRACTICE_INSURANCE_CO" length="40" />
        </property>
        <property name="malpracticeInsurancePolicyNo" type="string">
            <column name="RESOURCE_MALPRACTICE_INSURANCE_POLICY_NO" length="40" />
        </property>
        <property name="malpracticeInsuranceExpires" type="timestamp">
            <column name="RESOURCE_MALPRACTICE_INSURANCE_EXPIRES" length="23" />
        </property>
        <property name="expiryCpr" type="timestamp">
            <column name="RESOURCE_EXPIRY_CPR" length="23" />
        </property>
        <property name="expiryTb" type="timestamp">
            <column name="RESOURCE_EXPIRY_TB" length="23" />
        </property>
        <property name="expiryHepb" type="timestamp">
            <column name="RESOURCE_EXPIRY_HEPB" length="23" />
        </property>
        <property name="expiryAutoInsurance" type="timestamp">
            <column name="RESOURCE_EXPIRY_AUTO_INSURANCE" length="23" />
        </property>
        <property name="driversLicenseNo" type="string">
            <column name="RESOURCE_DRIVERS_LICENSE_NO" length="40" />
        </property>
        <property name="referenceRelease" type="boolean">
            <column name="RESOURCE_REFERENCE_RELEASE" />
        </property>
        <property name="hippaTraining" type="boolean">
            <column name="RESOURCE_HIPPA_TRAINING" />
        </property>
        <property name="agreementSigned" type="timestamp">
            <column name="RESOURCE_AGREEMENT_SIGNED" length="23" />
        </property>
        <property name="experienceNote" type="string">
            <column name="RESOURCE_EXPERIENCE_NOTE" length="2000" />
        </property>
        <property name="languageNote" type="string">
            <column name="RESOURCE_LANGUAGE_NOTE" length="2000" />
        </property>
        <property name="generalNote" type="string">
            <column name="RESOURCE_GENERAL_NOTE" length="2000" />
        </property>
        <property name="targetHourlyRate" type="double">
            <column name="RESOURCE_TARGET_HOURLY_RATE" precision="53" scale="0" />
        </property>
        <property name="availableForWork" type="timestamp">
            <column name="RESOURCE_AVAILABLE_FOR_WORK" length="23" />
        </property>
        <property name="availableForTravel" type="boolean">
            <column name="RESOURCE_AVAILABLE_TRAVEL" />
        </property>
        <property name="availableForPermanentPlacement" type="boolean">
            <column name="RESOURCE_AVAILABLE_PERMANENT_PLACEMENT" />
        </property>
        <property name="resumeReceived" type="timestamp">
            <column name="RESOURCE_RESUME_RECEIVED" length="23" />
        </property>
        <property name="backgroundCheck" type="timestamp">
            <column name="RESOURCE_BACKGROUND_CHECK" length="23" />
        </property>
        <property name="drugScreen" type="timestamp">
            <column name="RESOURCE_DRUG_SCREEN" length="23" />
        </property>
        <property name="resourceUpdated" type="timestamp">
            <column name="RESOURCE_UPDATED" length="23" />
        </property>
        <property name="resourceCreated" type="timestamp">
            <column name="RESOURCE_CREATED" length="23" not-null="true" />
        </property>
        <set name="activities" table="RESOURCE_ACTIVITY" lazy="true" cascade="persist,save-update,merge">
           <key column="RESOURCE_ID" />
           <many-to-many class="com.nkics.socialworkprn.swan.domain.Activity" column="ACTIVITY_ID"/>
        </set>
        <set name="dayOfWeeks" table="RESOURCE_DAY_OF_WEEK" lazy="true" cascade="persist,save-update,merge">
           <key column="RESOURCE_ID" />
           <many-to-many class="com.nkics.socialworkprn.swan.domain.DayOfWeek" column="DAY_OF_WEEK_ID"/>
        </set>
        <set name="experiences" table="RESOURCE_EXPERIENCE" lazy="true" cascade="persist,save-update,merge">
           <key column="RESOURCE_ID" />
           <many-to-many class="com.nkics.socialworkprn.swan.domain.Experience" column="EXPERIENCE_ID"/>
        </set>
        <set name="languages" table="RESOURCE_LANGUAGE" lazy="true" cascade="persist,save-update,merge">
           <key column="RESOURCE_ID" />
           <many-to-many class="com.nkics.socialworkprn.swan.domain.Language" column="LANGUAGE_ID"/>
        </set>
        <set name="resourcePhones" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.ResourcePhone" />
        </set>
        <set name="interviews" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.Interview" />
        </set>
        <set name="resourceMeetings" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.ResourceMeeting" />
        </set>
        <set name="workHistories" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.WorkHistory" />
        </set>
        <set name="educationHistories" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.EducationHistory" />
        </set>
        <set name="resourceStateCredentials" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.ResourceStateCredential" />
        </set>
        <set name="references" inverse="true" cascade="all,delete-orphan">
            <key>
                <column name="RESOURCE_ID" not-null="true" />
            </key>
            <one-to-many class="com.nkics.socialworkprn.swan.domain.Reference" />
        </set>
        <joined-subclass name="com.nkics.socialworkprn.swan.domain.Staff" table="STAFF">
         <key column="RESOURCE_ID" />
           <property name="left" type="timestamp">
               <column name="STAFF_LEFT" length="23" />
           </property>
           <set name="requisitionStaffTargets" inverse="true">
               <key>
                   <column name="STAFF_RESOURCE_ID" not-null="true" />
               </key>
               <one-to-many class="com.nkics.socialworkprn.swan.domain.RequisitionStaffTarget" />
           </set>
           <set name="supervisories" inverse="true">
               <key>
                   <column name="STAFF_RESOURCE_ID" not-null="true" />
               </key>
               <one-to-many class="com.nkics.socialworkprn.swan.domain.Supervisory" />
           </set>
           <joined-subclass name="com.nkics.socialworkprn.swan.domain.Coordinator" table="COORDINATOR">
            <key column="RESOURCE_ID" />
              <set name="coordinatorMeetings" inverse="true">
                  <key>
                      <column name="COORDINATOR_RESOURCE_ID" not-null="true" />
                  </key>
                  <one-to-many class="com.nkics.socialworkprn.swan.domain.Meeting" />
              </set>
              <set name="coordinatorInterviews" inverse="true">
                  <key>
                      <column name="COORDINATOR_RESOURCE_ID" not-null="true" />
                  </key>
                  <one-to-many class="com.nkics.socialworkprn.swan.domain.Interview" />
              </set>
              <set name="officeActivities" inverse="true">
                  <key>
                      <column name="COORDINATOR_RESOURCE_ID" not-null="true" />
                  </key>
                  <one-to-many class="com.nkics.socialworkprn.swan.domain.OfficeActivity" />
              </set>
            <set name="requisitions" inverse="true">
                  <key>
                      <column name="COORDINATOR_RESOURCE_ID" not-null="true" />
                  </key>
                  <one-to-many class="com.nkics.socialworkprn.swan.domain.Requisition" />
              </set>
              <set name="resources" inverse="true">
                  <key>
                      <column name="COORDINATOR_RESOURCE_ID" />
                  </key>
                  <one-to-many class="com.nkics.socialworkprn.swan.domain.Resource" />
              </set>
              <set name="coordinatorSupervisories" inverse="true">
                  <key>
                      <column name="COORDINATOR_RESOURCE_ID" />
                  </key>
                  <one-to-many class="com.nkics.socialworkprn.swan.domain.Supervisory" />
              </set>
         </joined-subclass>
        </joined-subclass>
    </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
Criteria resourceCriteria = getSession().createCriteria(Resource.class);
Example resourceExample = Example.create(exampleResource);
resourceExample.excludeProperty("resourceCreated");
resourceExample.excludeProperty("resourceUpdated");
resourceExample.setPropertySelector(ExcludeUnsetPropertySelector.SELECTOR);
resourceCriteria.add(resourceExample);
         
resourceCriteria.add(Restrictions.eq("class", "Resource"));  // This line is causing the Exception documented below.

if(exampleResource.getCoordinator()!=null)
{
   Criteria coordinatorCriteria = resourceCriteria.createCriteria("coordinator");
   if(exampleResource.getCoordinator().getId()!=null)
      coordinatorCriteria.add(Restrictions.eq("id", exampleResource.getCoordinator().getId()));
   Example coordinatorExample = Example.create(exampleResource.getCoordinator());
   coordinatorExample.excludeProperty("resourceCreated");
   coordinatorExample.excludeProperty("resourceUpdated");
   coordinatorExample.setPropertySelector(ExcludeUnsetPropertySelector.SELECTOR);
   coordinatorCriteria.add(coordinatorExample);
}

if(exampleResource.getOffice()!=null)
{
   Criteria officeCriteria = resourceCriteria.createCriteria("office");
   officeCriteria.add(Restrictions.eq("id", exampleResource.getOffice().getId()));
}

List resourceList = resourceCriteria.list();

Full stack trace of any exception that occurs:
2006-07-31 14:09:39,195 DEBUG [com.mchange.v2.sql.SqlUtils] - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: null; errorCode: 0]
com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 1.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.buildParamTypeDefinitions(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1552)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.nkics.socialworkprn.swan.persistence.hibernate.HibernateResourceDao.listByExample(HibernateResourceDao.java:203)
at com.nkics.socialworkprn.swan.service.defaults.DefaultCandidateService.getCandidateList(DefaultCandidateService.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy4.getCandidateList(Unknown Source)
at com.nkics.socialworkprn.swan.mvc.CandidateListController$CandidateListProvider.loadList(CandidateListController.java:111)
at org.springframework.beans.support.RefreshablePagedListHolder.refresh(RefreshablePagedListHolder.java:163)
at com.nkics.socialworkprn.swan.mvc.CandidateListController.onFormChange(CandidateListController.java:69)
at org.springframework.web.servlet.mvc.SimpleFormController.onFormChange(SimpleFormController.java:308)
at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:253)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:249)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:348)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:79)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.switchuser.SwitchUserProcessingFilter.doFilter(SwitchUserProcessingFilter.java:382)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:143)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:138)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:174)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:207)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:246)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:220)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:120)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)

Name and version of the database you are using: MS SQL Server Desktop Edition v8.00.760(SP3)

The generated SQL (show_sql=true):
Hibernate: select this_.RESOURCE_ID as RESOURCE1_15_1_, this_.COORDINATOR_RESOURCE_ID as COORDINA2_15_1_, this_.RESOURCE_DRIVERS_LICENSE_STATE_ID as RESOURCE3_15_1_, this_.OFFICE_ID as OFFICE4_15_1_, this_.RESOURCE_SOURCE_ID as RESOURCE5_15_1_, this_.STATE_ID as STATE6_15_1_, this_.RESOURCE_FIRST_NAME as RESOURCE7_15_1_, this_.RESOURCE_MIDDLE_NAME as RESOURCE8_15_1_, this_.RESOURCE_LAST_NAME as RESOURCE9_15_1_, this_.RESOURCE_NICKNAME as RESOURCE10_15_1_, this_.RESOURCE_ACTIVE as RESOURCE11_15_1_, this_.RESOURCE_ADDRESS_LINE1 as RESOURCE12_15_1_, this_.RESOURCE_ADDRESS_LINE2 as RESOURCE13_15_1_, this_.RESOURCE_ADDRESS_CITY as RESOURCE14_15_1_, this_.RESOURCE_ADDRESS_ZIP5 as RESOURCE15_15_1_, this_.RESOURCE_ADDRESS_ZIP4 as RESOURCE16_15_1_, this_.RESOURCE_EMERGENCY_CONTACT_NAME as RESOURCE17_15_1_, this_.RESOURCE_EMERGENCY_CONTACT_PHONE as RESOURCE18_15_1_, this_.RESOURCE_EMAIL as RESOURCE19_15_1_, this_.RESOURCE_HOURS_PER_WEEK as RESOURCE20_15_1_, this_.RESOURCE_SSN as RESOURCE21_15_1_, this_.RESOURCE_BIRTHDATE as RESOURCE22_15_1_, this_.RESOURCE_MALE as RESOURCE23_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_CO as RESOURCE24_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_POLICY_NO as RESOURCE25_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_EXPIRES as RESOURCE26_15_1_, this_.RESOURCE_EXPIRY_CPR as RESOURCE27_15_1_, this_.RESOURCE_EXPIRY_TB as RESOURCE28_15_1_, this_.RESOURCE_EXPIRY_HEPB as RESOURCE29_15_1_, this_.RESOURCE_EXPIRY_AUTO_INSURANCE as RESOURCE30_15_1_, this_.RESOURCE_DRIVERS_LICENSE_NO as RESOURCE31_15_1_, this_.RESOURCE_REFERENCE_RELEASE as RESOURCE32_15_1_, this_.RESOURCE_HIPPA_TRAINING as RESOURCE33_15_1_, this_.RESOURCE_AGREEMENT_SIGNED as RESOURCE34_15_1_, this_.RESOURCE_EXPERIENCE_NOTE as RESOURCE35_15_1_, this_.RESOURCE_LANGUAGE_NOTE as RESOURCE36_15_1_, this_.RESOURCE_GENERAL_NOTE as RESOURCE37_15_1_, this_.RESOURCE_TARGET_HOURLY_RATE as RESOURCE38_15_1_, this_.RESOURCE_AVAILABLE_FOR_WORK as RESOURCE39_15_1_, this_.RESOURCE_AVAILABLE_TRAVEL as RESOURCE40_15_1_, this_.RESOURCE_AVAILABLE_PERMANENT_PLACEMENT as RESOURCE41_15_1_, this_.RESOURCE_RESUME_RECEIVED as RESOURCE42_15_1_, this_.RESOURCE_BACKGROUND_CHECK as RESOURCE43_15_1_, this_.RESOURCE_DRUG_SCREEN as RESOURCE44_15_1_, this_.RESOURCE_UPDATED as RESOURCE45_15_1_, this_.RESOURCE_CREATED as RESOURCE46_15_1_, this_1_.STAFF_LEFT as STAFF2_20_1_, case when this_2_.RESOURCE_ID is not null then 2 when this_1_.RESOURCE_ID is not null then 1 when this_.RESOURCE_ID is not null then 0 end as clazz_1_, user2_.USER_ID as USER1_55_0_, user2_.USER_TYPE_ID as USER2_55_0_, user2_.USER_USERNAME as USER3_55_0_, user2_.USER_PASSWORD as USER4_55_0_, user2_.USER_ACTIVE as USER5_55_0_, user2_.USER_UPDATED as USER6_55_0_, user2_.USER_CREATED as USER7_55_0_ from RESOURCE this_ left outer join STAFF this_1_ on this_.RESOURCE_ID=this_1_.RESOURCE_ID left outer join COORDINATOR this_2_ on this_.RESOURCE_ID=this_2_.RESOURCE_ID left outer join USERS user2_ on this_.RESOURCE_ID=user2_.USER_ID where (1=1) and case when this_2_.RESOURCE_ID is not null then 2 when this_1_.RESOURCE_ID is not null then 1 when this_.RESOURCE_ID is not null then 0 end=?

Debug level Hibernate log excerpt:
2006-07-31 14:53:34,931 DEBUG [com.nkics.socialworkprn.swan.persistence.hibernate.HibernateResourceDao] - listing by example
2006-07-31 14:53:35,337 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-07-31 14:53:35,337 DEBUG [org.hibernate.SQL] - select this_.RESOURCE_ID as RESOURCE1_15_1_, this_.COORDINATOR_RESOURCE_ID as COORDINA2_15_1_, this_.RESOURCE_DRIVERS_LICENSE_STATE_ID as RESOURCE3_15_1_, this_.OFFICE_ID as OFFICE4_15_1_, this_.RESOURCE_SOURCE_ID as RESOURCE5_15_1_, this_.STATE_ID as STATE6_15_1_, this_.RESOURCE_FIRST_NAME as RESOURCE7_15_1_, this_.RESOURCE_MIDDLE_NAME as RESOURCE8_15_1_, this_.RESOURCE_LAST_NAME as RESOURCE9_15_1_, this_.RESOURCE_NICKNAME as RESOURCE10_15_1_, this_.RESOURCE_ACTIVE as RESOURCE11_15_1_, this_.RESOURCE_ADDRESS_LINE1 as RESOURCE12_15_1_, this_.RESOURCE_ADDRESS_LINE2 as RESOURCE13_15_1_, this_.RESOURCE_ADDRESS_CITY as RESOURCE14_15_1_, this_.RESOURCE_ADDRESS_ZIP5 as RESOURCE15_15_1_, this_.RESOURCE_ADDRESS_ZIP4 as RESOURCE16_15_1_, this_.RESOURCE_EMERGENCY_CONTACT_NAME as RESOURCE17_15_1_, this_.RESOURCE_EMERGENCY_CONTACT_PHONE as RESOURCE18_15_1_, this_.RESOURCE_EMAIL as RESOURCE19_15_1_, this_.RESOURCE_HOURS_PER_WEEK as RESOURCE20_15_1_, this_.RESOURCE_SSN as RESOURCE21_15_1_, this_.RESOURCE_BIRTHDATE as RESOURCE22_15_1_, this_.RESOURCE_MALE as RESOURCE23_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_CO as RESOURCE24_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_POLICY_NO as RESOURCE25_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_EXPIRES as RESOURCE26_15_1_, this_.RESOURCE_EXPIRY_CPR as RESOURCE27_15_1_, this_.RESOURCE_EXPIRY_TB as RESOURCE28_15_1_, this_.RESOURCE_EXPIRY_HEPB as RESOURCE29_15_1_, this_.RESOURCE_EXPIRY_AUTO_INSURANCE as RESOURCE30_15_1_, this_.RESOURCE_DRIVERS_LICENSE_NO as RESOURCE31_15_1_, this_.RESOURCE_REFERENCE_RELEASE as RESOURCE32_15_1_, this_.RESOURCE_HIPPA_TRAINING as RESOURCE33_15_1_, this_.RESOURCE_AGREEMENT_SIGNED as RESOURCE34_15_1_, this_.RESOURCE_EXPERIENCE_NOTE as RESOURCE35_15_1_, this_.RESOURCE_LANGUAGE_NOTE as RESOURCE36_15_1_, this_.RESOURCE_GENERAL_NOTE as RESOURCE37_15_1_, this_.RESOURCE_TARGET_HOURLY_RATE as RESOURCE38_15_1_, this_.RESOURCE_AVAILABLE_FOR_WORK as RESOURCE39_15_1_, this_.RESOURCE_AVAILABLE_TRAVEL as RESOURCE40_15_1_, this_.RESOURCE_AVAILABLE_PERMANENT_PLACEMENT as RESOURCE41_15_1_, this_.RESOURCE_RESUME_RECEIVED as RESOURCE42_15_1_, this_.RESOURCE_BACKGROUND_CHECK as RESOURCE43_15_1_, this_.RESOURCE_DRUG_SCREEN as RESOURCE44_15_1_, this_.RESOURCE_UPDATED as RESOURCE45_15_1_, this_.RESOURCE_CREATED as RESOURCE46_15_1_, this_1_.STAFF_LEFT as STAFF2_20_1_, case when this_2_.RESOURCE_ID is not null then 2 when this_1_.RESOURCE_ID is not null then 1 when this_.RESOURCE_ID is not null then 0 end as clazz_1_, user2_.USER_ID as USER1_55_0_, user2_.USER_TYPE_ID as USER2_55_0_, user2_.USER_USERNAME as USER3_55_0_, user2_.USER_PASSWORD as USER4_55_0_, user2_.USER_ACTIVE as USER5_55_0_, user2_.USER_UPDATED as USER6_55_0_, user2_.USER_CREATED as USER7_55_0_ from RESOURCE this_ left outer join STAFF this_1_ on this_.RESOURCE_ID=this_1_.RESOURCE_ID left outer join COORDINATOR this_2_ on this_.RESOURCE_ID=this_2_.RESOURCE_ID left outer join USERS user2_ on this_.RESOURCE_ID=user2_.USER_ID where (1=1) and case when this_2_.RESOURCE_ID is not null then 2 when this_1_.RESOURCE_ID is not null then 1 when this_.RESOURCE_ID is not null then 0 end=?
Hibernate: select this_.RESOURCE_ID as RESOURCE1_15_1_, this_.COORDINATOR_RESOURCE_ID as COORDINA2_15_1_, this_.RESOURCE_DRIVERS_LICENSE_STATE_ID as RESOURCE3_15_1_, this_.OFFICE_ID as OFFICE4_15_1_, this_.RESOURCE_SOURCE_ID as RESOURCE5_15_1_, this_.STATE_ID as STATE6_15_1_, this_.RESOURCE_FIRST_NAME as RESOURCE7_15_1_, this_.RESOURCE_MIDDLE_NAME as RESOURCE8_15_1_, this_.RESOURCE_LAST_NAME as RESOURCE9_15_1_, this_.RESOURCE_NICKNAME as RESOURCE10_15_1_, this_.RESOURCE_ACTIVE as RESOURCE11_15_1_, this_.RESOURCE_ADDRESS_LINE1 as RESOURCE12_15_1_, this_.RESOURCE_ADDRESS_LINE2 as RESOURCE13_15_1_, this_.RESOURCE_ADDRESS_CITY as RESOURCE14_15_1_, this_.RESOURCE_ADDRESS_ZIP5 as RESOURCE15_15_1_, this_.RESOURCE_ADDRESS_ZIP4 as RESOURCE16_15_1_, this_.RESOURCE_EMERGENCY_CONTACT_NAME as RESOURCE17_15_1_, this_.RESOURCE_EMERGENCY_CONTACT_PHONE as RESOURCE18_15_1_, this_.RESOURCE_EMAIL as RESOURCE19_15_1_, this_.RESOURCE_HOURS_PER_WEEK as RESOURCE20_15_1_, this_.RESOURCE_SSN as RESOURCE21_15_1_, this_.RESOURCE_BIRTHDATE as RESOURCE22_15_1_, this_.RESOURCE_MALE as RESOURCE23_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_CO as RESOURCE24_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_POLICY_NO as RESOURCE25_15_1_, this_.RESOURCE_MALPRACTICE_INSURANCE_EXPIRES as RESOURCE26_15_1_, this_.RESOURCE_EXPIRY_CPR as RESOURCE27_15_1_, this_.RESOURCE_EXPIRY_TB as RESOURCE28_15_1_, this_.RESOURCE_EXPIRY_HEPB as RESOURCE29_15_1_, this_.RESOURCE_EXPIRY_AUTO_INSURANCE as RESOURCE30_15_1_, this_.RESOURCE_DRIVERS_LICENSE_NO as RESOURCE31_15_1_, this_.RESOURCE_REFERENCE_RELEASE as RESOURCE32_15_1_, this_.RESOURCE_HIPPA_TRAINING as RESOURCE33_15_1_, this_.RESOURCE_AGREEMENT_SIGNED as RESOURCE34_15_1_, this_.RESOURCE_EXPERIENCE_NOTE as RESOURCE35_15_1_, this_.RESOURCE_LANGUAGE_NOTE as RESOURCE36_15_1_, this_.RESOURCE_GENERAL_NOTE as RESOURCE37_15_1_, this_.RESOURCE_TARGET_HOURLY_RATE as RESOURCE38_15_1_, this_.RESOURCE_AVAILABLE_FOR_WORK as RESOURCE39_15_1_, this_.RESOURCE_AVAILABLE_TRAVEL as RESOURCE40_15_1_, this_.RESOURCE_AVAILABLE_PERMANENT_PLACEMENT as RESOURCE41_15_1_, this_.RESOURCE_RESUME_RECEIVED as RESOURCE42_15_1_, this_.RESOURCE_BACKGROUND_CHECK as RESOURCE43_15_1_, this_.RESOURCE_DRUG_SCREEN as RESOURCE44_15_1_, this_.RESOURCE_UPDATED as RESOURCE45_15_1_, this_.RESOURCE_CREATED as RESOURCE46_15_1_, this_1_.STAFF_LEFT as STAFF2_20_1_, case when this_2_.RESOURCE_ID is not null then 2 when this_1_.RESOURCE_ID is not null then 1 when this_.RESOURCE_ID is not null then 0 end as clazz_1_, user2_.USER_ID as USER1_55_0_, user2_.USER_TYPE_ID as USER2_55_0_, user2_.USER_USERNAME as USER3_55_0_, user2_.USER_PASSWORD as USER4_55_0_, user2_.USER_ACTIVE as USER5_55_0_, user2_.USER_UPDATED as USER6_55_0_, user2_.USER_CREATED as USER7_55_0_ from RESOURCE this_ left outer join STAFF this_1_ on this_.RESOURCE_ID=this_1_.RESOURCE_ID left outer join COORDINATOR this_2_ on this_.RESOURCE_ID=this_2_.RESOURCE_ID left outer join USERS user2_ on this_.RESOURCE_ID=user2_.USER_ID where (1=1) and case when this_2_.RESOURCE_ID is not null then 2 when this_1_.RESOURCE_ID is not null then 1 when this_.RESOURCE_ID is not null then 0 end=?
2006-07-31 14:53:35,337 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
2006-07-31 14:53:35,337 DEBUG [org.hibernate.type.IntegerType] - binding 'Resource' to parameter: 1
2006-07-31 14:53:35,337 INFO [org.hibernate.type.IntegerType] - could not bind value 'Resource' to parameter: 1
2006-07-31 14:53:35,369 DEBUG [com.mchange.v2.sql.SqlUtils] - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: null; errorCode: 0]
com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 1.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.buildParamTypeDefinitions(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1552)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.nkics.socialworkprn.swan.persistence.hibernate.HibernateResourceDao.listByExample(HibernateResourceDao.java:203)
at com.nkics.socialworkprn.swan.service.defaults.DefaultCandidateService.getCandidateList(DefaultCandidateService.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy4.getCandidateList(Unknown Source)
at com.nkics.socialworkprn.swan.mvc.CandidateListController$CandidateListProvider.loadList(CandidateListController.java:111)
at org.springframework.beans.support.RefreshablePagedListHolder.refresh(RefreshablePagedListHolder.java:163)
at com.nkics.socialworkprn.swan.mvc.CandidateListController.formBackingObject(CandidateListController.java:55)
at org.springframework.web.servlet.mvc.AbstractFormController.handleInvalidSubmit(AbstractFormController.java:647)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:256)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:348)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:292)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:79)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.switchuser.SwitchUserProcessingFilter.doFilter(SwitchUserProcessingFilter.java:382)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:143)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:138)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:174)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:207)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:246)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:220)
at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:303)
at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:120)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Notes
I am trying to execute a QBE which excludes any subclasses of the class (Resource.class) requested.


Top
 Profile  
 
 Post subject: Solution
PostPosted: Mon Jul 31, 2006 4:37 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
Solution
By default the Criteria.list() method returns any object that matches the class or a subclass of the class specified in the Criteria. To limit your QBE to one class within a class hierarchy you must restrict the pseudo property "class" to the class you want to retrieve. This eliminates the need for a descriminator field within your objects, which prevents the descriminator field and subclass tables from getting out of sync.

Example
With a class hierarchy like Coordinator extends Staff extends Resource, this example creates a query which does not include subtypes of the class specified.
Code:
Criteria resourceCriteria = getSession().createCriteria(Resource.class);
resourceCriteria.add(Restrictions.eq("class", Resource.class));
List resourceList = resourceCriteria.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.