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