| Hibernate version: CVS Checkout 09/05/2004
 Mapping documents:
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
 <hibernate-mapping>
 
 <class name="test.Object1" lazy="true">
 <id name="id" type="java.lang.Integer">
 <generator class="native">
 </generator>
 </id>
 <set name="translations" cascade="all" inverse="true" lazy="true" where="discriminator = 1">
 <key column="object_id"/>
 <one-to-many class="test.Translation"/>
 </set>
 
 </class>
 
 </hibernate-mapping>
 
 Code between sessionFactory.openSession() and session.close():
 
 List l = session.find("select o1 from Object1 as o1 inner join o1.translations t where t.text like '%de%'");
 Iterator it = l.iterator();
 while (it.hasNext()) {
 Object1 o1 = (Object1)it.next();
 System.out.println(o1.getId());
 }
 
 List trans = session.createCriteria(Object1.class)
 .createCriteria("translations")
 .add( Expression.like("text", "de", MatchMode.ANYWHERE))
 .list();
 
 for ( it = trans.iterator(); it.hasNext();) {
 Object1 o1 = (Object1)it.next();
 System.out.println(o1.getId());
 }
 
 
 Name and version of the database you are using:MS SQL Server 2000
 
 I add a where attribute to the translation set. The HQL Version of the Query creates this SQL Statement:
 
 select object10_.id as id from Object1 object10_ inner join Translation translatio1_ on object10_.id=translatio1_.object_id where translatio1_.discriminator = 1 and ((translatio1_.text like '%de%' ))
 
 
 The Criteria Version creates this statement:
 select this.id as id1_, x0_.id as id0_, x0_.locale as locale0_, x0_.text as text0_, x0_.discriminator as discrimi4_0_, x0_.object_id as object_id0_ from Object1 this inner join Translation x0_ on this.id=x0_.object_id where x0_.text like ?
 
 The problem is that the Criteria Version does not add the where clause (discriminator = 1)  to the statement. Is this probably a bug?
 
 
 |