-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria not generating proper SQL statement when HSQL does
PostPosted: Thu Jan 18, 2007 5:22 pm 
Newbie

Joined: Wed Jun 21, 2006 7:10 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3,2,1qa

Mapping documents:
There are 2 classes

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 package="com.duanemorris.dmdata.bo">
   <class
      name="Practices"
      table="Practices"
   >
      <meta attribute="sync-DAO">true</meta>
      <id
         name="Id"
         type="integer"
         column="Practice_ID"
      >
         <generator class="native"/>
      </id>

      <property
         name="PracticeDesc"
         column="Practice_Desc"
         type="string"
         not-null="true"
         length="250"
      />
      <property
         name="PracticeShortdesc"
         column="Practice_ShortDesc"
         type="string"
         not-null="false"
         length="30"
      />
      <property
         name="Featured"
         column="Featured"
         type="integer"
         not-null="false"
         length="1"
      />
      <property
         name="FeaturedDisplayorder"
         column="FeaturedDisplayorder"
         type="integer"
         not-null="false"
         length="10"
      />
      <property
         name="PDFFilename"
         column="PDFFilename"
         type="string"
         not-null="false"
         length="400"
      />
      <property
         name="AccountingCode"
         column="AccountingCode"
         type="string"
         not-null="false"
         length="15"
      />
      <property
         name="AccountingName"
         column="AccountingName"
         type="string"
         not-null="false"
         length="100"
      />
      <property
         name="ParentPracticeLink"
         column="Parent_Practice_Link"
         type="integer"
         not-null="false"
         length="10"
      />
      <property
         name="Type"
         column="Type"
         type="string"
         not-null="false"
         length="1"
      />
      <property
         name="MopLink"
         column="MOP_Link"
         type="integer"
         not-null="false"
         length="10"
      />
      <property
         name="Retired"
         column="Retired"
         type="integer"
         not-null="true"
         length="10"
      />
      <property
         name="CompanyLink"
         column="Company_Link"
         type="integer"
         not-null="false"
         length="10"
      />
      
      <set name="PracticesWebText" where="WebProject_Link = 0">
         <key column="objectitem_link" />      
         <one-to-many class="PracticeWebText" />
      </set>
      
      <set name="PracticesWebPublishing" >
         <key column="objectitem_link" />     
         <one-to-many class="PracticesWebPublishing" />
      </set>   


   </class>   
   <class
      name="WebPublishing"
      table="DMwebPublishingCatalog"
   >
   
      <meta attribute="sync-DAO">true</meta>
      <id
         name="id"
         type="string"
         column="ObjectItem_Link"
      >
         <generator class="native"/>   
      </id>

      <discriminator
         column="ObjectType_Link"
         type="string"
         not-null="true"
         insert="false"
         force="true"
       />

      <property
         name="ActiveStatus"
         column="ActiveStatus"
         type="string"
         not-null="true"
         length="1"
      />
      <property
         name="DisplayOrder"
         column="DisplayOrder"
         type="integer"
         not-null="true"
         length="10"
      />
      <property
         name="Private"
         column="Private"
         type="boolean"
         not-null="true"
         length="1"
      />
      <property
         name="TopImageName"
         column="TopImageName"
         type="string"
         not-null="false"
         length="200"
      />
      <property
         name="PageImageName"
         column="PageImageName"
         type="string"
         not-null="false"
         length="200"
      />
      <property
         name="Comments"
         column="Comments"
         type="string"
         not-null="false"
         length="500"
      />
      
      <subclass discriminator-value="OFC" name="OfficeWebPublishing" />
      
      <subclass discriminator-value="PPL" name="PeopleWebPublishing" />
      
      <subclass discriminator-value="IND" name="IndustryWebPublishing" />
   
      <subclass discriminator-value="PRC" name="PracticesWebPublishing" />
      
      <subclass discriminator-value="CDY" name="CaseStudyWebPublishing" />

      <subclass discriminator-value="PUB" name="PublicationsWebPublishing" />
      
      <subclass discriminator-value="EVT" name="EventsWebPublishing" />


   </class>   
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
String props[] = { Practices.PROP_RETIRED };
Object values[] = { new Integer(0) };
Criteria c = masterDAO.getPracticesDAO().findFiltered(masterDAO.getPracticesDAO().getSession(), props, values, null);
      c = c.add(Restrictions.isNotEmpty("PracticesWebPublishing"));

Here is the code for 'findfiltered'
Code:
   public Criteria findFiltered(Session s, String[] propName, Object[] filter, Order order) {
      Criteria crit = s.createCriteria(getReferenceClass());
      
      for (int i = 0; i < propName.length; i++)
         crit.add(Expression.eq(propName[i], filter[i]));
      
      if (order != null)
         crit.addOrder(order);
   
      return crit;
   }

OR

Code:
Query q = masterDAO.getPracticesDAO().getSession().createQuery("from Practices p where p.Retired = 0 and p.PracticesWebPublishing is not empty order by p.PracticeDesc");

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Microsoft SQL Server 2000
The generated SQL (show_sql=true):
The Criteria generates:
Code:
select this_.Practice_ID as Practice1_9_0_, this_.Practice_Desc as Practice2_9_0_, this_.Practice_ShortDesc as Practice3_9_0_, this_.Featured as Featured9_0_, this_.FeaturedDisplayorder as Featured5_9_0_, this_.PDFFilename as PDFFilen6_9_0_, this_.AccountingCode as Accounti7_9_0_, this_.AccountingName as Accounti8_9_0_, this_.Parent_Practice_Link as Parent9_9_0_, this_.Type as Type9_0_, this_.MOP_Link as MOP11_9_0_, this_.Retired as Retired9_0_, this_.Company_Link as Company13_9_0_ from Practices this_ where this_.Retired=? and exists (select 1 from DMwebPublishingCatalog where this_.Practice_ID=objectitem_link)


The HSQL generates:
Code:
select practices0_.Practice_ID as Practice1_9_, practices0_.Practice_Desc as Practice2_9_, practices0_.Practice_ShortDesc as Practice3_9_, practices0_.Featured as Featured9_, practices0_.FeaturedDisplayorder as Featured5_9_, practices0_.PDFFilename as PDFFilen6_9_, practices0_.AccountingCode as Accounti7_9_, practices0_.AccountingName as Accounti8_9_, practices0_.Parent_Practice_Link as Parent9_9_, practices0_.Type as Type9_, practices0_.MOP_Link as MOP11_9_, practices0_.Retired as Retired9_, practices0_.Company_Link as Company13_9_ from Practices practices0_ where practices0_.Retired=0 and (exists (select practicesw1_.ObjectItem_Link from DMwebPublishingCatalog practicesw1_ where practices0_.Practice_ID=practicesw1_.objectitem_link and practicesw1_.ObjectType_Link='PRC')) order by practices0_.Practice_Desc



PLEASE NOTE:
The HSQL generated SQL correctly includes a second delimiter in the exists clause (practicesw1_.ObjectType_Link='PRC'). The SQL generated by the criteria does not have this delimiter.


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

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.