-->
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: HQL and Criteria Query return different results
PostPosted: Thu Aug 26, 2004 12:11 pm 
Newbie

Joined: Mon May 31, 2004 9:22 am
Posts: 5
Location: Austria
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 package="jlaver.database">
        <class name="Ort" table="ort_Ort">
                <id name="id" type="long" column="ort_id">
                        <generator class="sequence">
                            <param name="sequence"> ort_Ort_ort_id_seq </param>
                        </generator>
                </id>
               
                <timestamp name="letzteAenderung" column="ort_letzteaenderung"/>
                <many-to-one name="userLetzteAenderung" column="user_id_letzteaenderung" class="jlaver.database.config.User" />   

                <property name="plz" column="ort_plz" type="int"/>
                <property name="name" column="ort_name" type="string"/>
                <many-to-one name="staat" column="staa_id" class="Staat" />       
        </class>
</hibernate-mapping>

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 package="jlaver.database">
        <class name="Staat" table="staa_staat">
                <id name="id" type="long" column="staa_id">
                        <generator class="sequence">
                            <param name="sequence"> staa_staat_staa_id_seq </param>
                        </generator>
                </id>
                <timestamp name="letzteAenderung" column="staa_letzteaenderung"/>
                <many-to-one name="userLetzteAenderung" column="user_id_letzteaenderung" class="jlaver.database.config.User" />   
       
                <property name="laenderkennzeichen" type="string" column="staa_lkz"/>
                <property name="bezeichnung" column="staa_bez" type="string"/>
                <property name="vorwahl" column="staa_vorwahl" type="int"/>
               
        </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

HQL Query:

Code:
Query q=s.createQuery("select distinct o from Ort o where o.staat=:staat");
q.setEntity("staat", staat);
return (java.util.List<Ort>) q.list();


Criteria Query:

Code:
Criteria c=s.createCriteria(Ort.class);
c.createCriteria("staat").add(Example.create(s));
return (java.util.List<Ort>) c.list();


Full stack trace of any exception that occurs:

no exception

Name and version of the database you are using:

Postgresql 7.3


My problem is, that the Criteria query returns no result and the HQL query does if I execute them with a previously loaded "Staat".

If I exclude the "vorwahl" property from the example the Criteria query returns the same results as the HQL query.

Is there any difference in processing int-Values between Criteria and HQL queries? (Of course the "vorwahl" of the loaded "Staat" is correctly set...)

Thanks,
Wolfgang


Top
 Profile  
 
 Post subject: wrong syntax?
PostPosted: Wed Sep 22, 2004 5:01 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
>>c.createCriteria("staat").add(Example.create(s));

this does not look correct. the createCriteria method needs a Staat.class argument IIRC.


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.