I'm using an Expression.in on a component class. When executing the code I an empty list.
When using the generated SQL in DBVisualizer adding the variables it returns the expectet list.
Am I doing something wrong or have I stumpled over a bug?
I just turned on debug log level and can now see, that it's a bug.
Parameters are bound in the wrong order - see Debug level Hibernate log excerpt.
Paramters are
bound 9999, 9999, 01, 03
should be 9999, 01, 9999, 03 according to
SQL: where (this_.ejerlavskode, this_.matrikelnr) in ((?, ?), (?, ?))
Parameter pairs are by class Matrikelbetegnelse (ejerlavskode=9999, matrikenr=01)
Best regards,
Thomas Andersen
Hibernate version:
Hibernate 3.1.2
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
<class
name="dk.kms.minimaks.sagsadministration.sagsdata.model.Sagsadvarsel"
table="sagsadvarsel"
>
<id
name="id"
column="id"
type="long"
>
<generator class="native">
<param name="sequence">sagsadvarsel_id_seq</param>
</generator>
</id>
<version
name="version"
column="version"
type="long"
/>
<property
name="datoTid"
type="java.util.Date"
update="true"
insert="true"
column="datoTid"
not-null="false"
/>
<component
name="matrikelbetegnelse"
class="dk.kms.minimaks.sagsadministration.sagsdata.model.Matrikelbetegnelse"
>
<property
name="ejerlavskode"
type="java.lang.Long"
update="true"
insert="true"
column="ejerlavskode"
/>
<property
name="matrikelnr"
type="java.lang.String"
update="true"
insert="true"
column="matrikelnr"
length="20"
/>
</component>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Long ejerlav = new Long(9999);
final Matrikelbetegnelse[] matrikelbetegnelser = new Matrikelbetegnelse[2];
matrikelbetegnelser[0] = new Matrikelbetegnelse(ejerlav, "01");
matrikelbetegnelser[1] = new Matrikelbetegnelse(ejerlav, "03");
List list = session.createCriteria(Sagsadvarsel.class)
.add(Expression.in("matrikelbetegnelse",matrikelbetegnelser))
.list();
log.debug("list " + list.size());
import java.util.Date;
import java.io.Serializable;
/**
* @hibernate.class table="sagsadvarsel"
*/
public class Sagsadvarsel implements Serializable{
private long id;
private long version;
private Date datoTid;
private Matrikelbetegnelse matrikelbetegnelse;
/**
* @return
* @hibernate.id generator-class="native"
*/
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
/**
* Udlever versionsnummer for forekomsten. Feltet ajourføres af Hibernate, som samtidig bruger det til at
* forhindre samtidig opdatering fra to processer.
* hibernate.version
* @return
*/
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
/**
* Udlever datotid (Dato og tidspunkt for sagsadvarsel).
*
* @hibernate.property not-null="false"
* @return datotid
*/
public Date getDatoTid() {
return datoTid;
}
public void setDatoTid(Date datoTid) {
this.datoTid = datoTid;
}
/**
* Udlever Matrikelbetegnelse.
*
* @hibernate.component
*/
public Matrikelbetegnelse getMatrikelbetegnelse() {
return matrikelbetegnelse;
}
public void setMatrikelbetegnelse(Matrikelbetegnelse matrikelbetegnelse) {
this.matrikelbetegnelse = matrikelbetegnelse;
}
}
import java.io.Serializable;
/**
*/
public class Matrikelbetegnelse {
private Long ejerlavskode ;
private String matrikelnr ;
public Matrikelbetegnelse() {
}
public Matrikelbetegnelse(Long ejerlavskode, String matrikelnummer) {
this.ejerlavskode = ejerlavskode;
this.matrikelnr = matrikelnummer;
}
/**
*
* @return
* @hibernate.property
*/
public Long getEjerlavskode() {
return ejerlavskode;
}
public void setEjerlavskode(Long ejerlavskode) {
this.ejerlavskode = ejerlavskode;
}
/**
*
* @return
* @hibernate.property length="20"
*/
public String getMatrikelnr() {
return matrikelnr;
}
public void setMatrikelnr(String matrikelnr) {
this.matrikelnr = matrikelnr;
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Matrikelbetegnelse)) return false;
final Matrikelbetegnelse matrikelbetegnelse = (Matrikelbetegnelse) o;
if (!ejerlavskode.equals(matrikelbetegnelse.ejerlavskode)) return false;
if (!matrikelnr.equals(matrikelbetegnelse.matrikelnr)) return false;
return true;
}
public int hashCode() {
int result;
result = ejerlavskode.hashCode();
result = 29 * result + matrikelnr.hashCode();
return result;
}
}
Full stack trace of any exception that occurs:
No exception, just an empty result.
Name and version of the database you are using:
Oracle 10g Enteprise Edition release 10.1.0.2.0
The generated SQL (show_sql=true):
Hibernate: select this_.id as id34_0_, this_.datoTid as datoTid34_0_, this_.ejerlavskode as ejerlavs3_34_0_, this_.matrikelnr as matrikelnr34_0_, this_.fk_sag_id as fk5_34_0_, this_.brugerId as brugerId34_0_, this_.tidsstempel as tidsstem7_34_0_, this_.gyldig_fra as gyldig8_34_0_, this_.gyldig_til as gyldig9_34_0_, this_.oprind_id as oprind10_34_0_ from tan.sagsadvarsel this_ where (this_.ejerlavskode, this_.matrikelnr) in ((?, ?), (?, ?))
Debug level Hibernate log excerpt:
14:02:58,631 DEBUG [CID= ] [org.hibernate.jdbc.AbstractBatcher.log(AbstractBatcher.java:346)] select this_.id as id34_1_, this_.version as version34_1_, this_.datoTid as datoTid34_1_, this_.ejerlavskode as ejerlavs4_34_1_, this_.matrikelnr as matrikelnr34_1_, this_.fk_sag_id as fk6_34_1_, this_.brugerId as brugerId34_1_, this_.tidsstempel as tidsstem8_34_1_, this_.gyldig_fra as gyldig9_34_1_, this_.gyldig_til as gyldig10_34_1_, this_.oprind_id as oprind11_34_1_, s1_.id as id15_0_, s1_.version as version15_0_, s1_.sagsId as sagsId15_0_, s1_.symbolskNavn as symbolsk4_15_0_, s1_.kms_journalnummer as kms5_15_0_, s1_.journaliseringsDato as journali6_15_0_, s1_.rekvirentRef as rekviren7_15_0_, s1_.enum_sagskategori as enum8_15_0_, s1_.enum_prioritet as enum9_15_0_, s1_.tidsfrist as tidsfrist15_0_, s1_.saerligAftale as saerlig11_15_0_, s1_.matrikelnr as matrikelnr15_0_, s1_.ejerlavskode as ejerlav13_15_0_, s1_.afventAntalHoeringssvar as afventA14_15_0_, s1_.afventAntalSupplDok as afventA15_15_0_, s1_.maaIkkeSlettes as maaIkke16_15_0_, s1_.erForaeldet as erForae17_15_0_, s1_.brugerId as brugerId15_0_, s1_.tidsstempel as tidsste19_15_0_, s1_.gyldig_fra as gyldig20_15_0_, s1_.gyldig_til as gyldig21_15_0_, s1_.oprind_id as oprind22_15_0_, s1_.fk_aktoer_indsender_id as fk23_15_0_, s1_.fk_aktoer_rekvirent_id as fk24_15_0_, s1_.fk_aktoer_revisor_id as fk25_15_0_, s1_.fk_sagsbehandlerteam_id as fk26_15_0_, s1_.fk_sagspakke_id as fk27_15_0_, s1_.fk_sagsresume_id as fk28_15_0_, s1_.aflysningsmeddelelse as aflysni29_15_0_, s1_.fk_samlesag_id as fk30_15_0_ from tan.sagsadvarsel this_ inner join tan.sag s1_ on this_.fk_sag_id=s1_.id where (this_.ejerlavskode, this_.matrikelnr) in ((?, ?), (?, ?)) and not s1_.sagsId=? order by this_.fk_sag_id asc, this_.ejerlavskode asc, this_.matrikelnr asc
Hibernate: select this_.id as id34_1_, this_.version as version34_1_, this_.datoTid as datoTid34_1_, this_.ejerlavskode as ejerlavs4_34_1_, this_.matrikelnr as matrikelnr34_1_, this_.fk_sag_id as fk6_34_1_, this_.brugerId as brugerId34_1_, this_.tidsstempel as tidsstem8_34_1_, this_.gyldig_fra as gyldig9_34_1_, this_.gyldig_til as gyldig10_34_1_, this_.oprind_id as oprind11_34_1_, s1_.id as id15_0_, s1_.version as version15_0_, s1_.sagsId as sagsId15_0_, s1_.symbolskNavn as symbolsk4_15_0_, s1_.kms_journalnummer as kms5_15_0_, s1_.journaliseringsDato as journali6_15_0_, s1_.rekvirentRef as rekviren7_15_0_, s1_.enum_sagskategori as enum8_15_0_, s1_.enum_prioritet as enum9_15_0_, s1_.tidsfrist as tidsfrist15_0_, s1_.saerligAftale as saerlig11_15_0_, s1_.matrikelnr as matrikelnr15_0_, s1_.ejerlavskode as ejerlav13_15_0_, s1_.afventAntalHoeringssvar as afventA14_15_0_, s1_.afventAntalSupplDok as afventA15_15_0_, s1_.maaIkkeSlettes as maaIkke16_15_0_, s1_.erForaeldet as erForae17_15_0_, s1_.brugerId as brugerId15_0_, s1_.tidsstempel as tidsste19_15_0_, s1_.gyldig_fra as gyldig20_15_0_, s1_.gyldig_til as gyldig21_15_0_, s1_.oprind_id as oprind22_15_0_, s1_.fk_aktoer_indsender_id as fk23_15_0_, s1_.fk_aktoer_rekvirent_id as fk24_15_0_, s1_.fk_aktoer_revisor_id as fk25_15_0_, s1_.fk_sagsbehandlerteam_id as fk26_15_0_, s1_.fk_sagspakke_id as fk27_15_0_, s1_.fk_sagsresume_id as fk28_15_0_, s1_.aflysningsmeddelelse as aflysni29_15_0_, s1_.fk_samlesag_id as fk30_15_0_ from tan.sagsadvarsel this_ inner join tan.sag s1_ on this_.fk_sag_id=s1_.id where (this_.ejerlavskode, this_.matrikelnr) in ((?, ?), (?, ?)) and not s1_.sagsId=? order by this_.fk_sag_id asc, this_.ejerlavskode asc, this_.matrikelnr asc
14:02:58,641 DEBUG [CID= ] [org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:424)] preparing statement
14:02:58,641 DEBUG [CID= ] [org.hibernate.type.NullableType.nullSafeSet(NullableType.java:79)] binding '9999' to parameter: 1
14:02:58,641 DEBUG [CID= ] [org.hibernate.type.NullableType.nullSafeSet(NullableType.java:79)] binding '9999' to parameter: 2
14:02:58,641 DEBUG [CID= ] [org.hibernate.type.NullableType.nullSafeSet(NullableType.java:79)] binding '01' to parameter: 3
14:02:58,641 DEBUG [CID= ] [org.hibernate.type.NullableType.nullSafeSet(NullableType.java:79)] binding '03' to parameter: 4
14:02:58,701 DEBUG [CID= ] [org.hibernate.jdbc.AbstractBatcher.logOpenResults(AbstractBatcher.java:327)] about to open ResultSet (open ResultSets: 0, globally: 0)
|