-->
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: Bug in Criteria API?
PostPosted: Sun Sep 05, 2004 3:09 pm 
Newbie

Joined: Fri Oct 03, 2003 10:46 pm
Posts: 8
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?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 05, 2004 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a known problem in Hibernate 2.x that was fixed in Hibernate3


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.