Ho un'entità con una chiave incorporata. L'entità ha solo la chiave come campo e la chiave ha 7 campi, alcuni dei quali possono essere nulli.Elenco nullo restituito dalla query di ibernazione con ID incorporato
Quando si esegue la seguente domanda:
Criteria criteria = session.createCriteria(getPersistentClass());
criteria.add(Restrictions.eq("id.profPropertyId", profileExtensionName));
Object obj = criteria.list();
log.info(obj);
return (List<ProfileExtensions>) obj;
ottengo il numero corretto di risultati, ma ogni risultato è nullo (cioè ho un elenco di 4000 oggetti nulli). Ho provato ad utilizzare sia una query HQL che i criteri, ma entrambi danno lo stesso risultato.
Le classi di mapping sono state generate da un database esistente.
L'SQL generato per la query è la seguente
select this_.PROF_DATA_TYPE as PROF1_14_0_, this_.PROF_EXT_KEY as PROF2_14_0_,
this_.PROF_KEY as PROF3_14_0_, this_.PROF_NAME as PROF4_14_0_,
this_.PROF_PROPERTY_ID as PROF5_14_0_, this_.PROF_VALUE as PROF6_14_0_,
this_.PROF_VALUE_EXTENDED as PROF7_14_0_
from EMPINST.PROFILE_EXTENSIONS this_
where this_.PROF_PROPERTY_ID=?
sembra che dovrebbe restituire i dati corretti.
Il file di mapping è piuttosto semplice (e generato dallo schema:.
// Generated Oct 18, 2010 11:08:08 PM by Hibernate Tools 3.2.2.GA
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name="PROFILE_EXTENSIONS"
,schema="EMPINST"
, uniqueConstraints = @UniqueConstraint(columnNames={"PROF_KEY", "PROF_PROPERTY_ID"}))
public class ProfileExtensions implements java.io.Serializable {
private ProfileExtensionsId id;
public ProfileExtensions() {
}
public ProfileExtensions(ProfileExtensionsId id) {
this.id = id;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name="profKey", [email protected](name="PROF_KEY", nullable=false, length=36)),
@AttributeOverride(name="profPropertyId", [email protected](name="PROF_PROPERTY_ID", nullable=false, length=64)),
@AttributeOverride(name="profExtKey", [email protected](name="PROF_EXT_KEY", length=256)),
@AttributeOverride(name="profName", [email protected](name="PROF_NAME", length=256)),
@AttributeOverride(name="profDataType", [email protected](name="PROF_DATA_TYPE", length=64)),
@AttributeOverride(name="profValue", [email protected](name="PROF_VALUE", length=1024)),
@AttributeOverride(name="profValueExtended", [email protected](name="PROF_VALUE_EXTENDED")) })
public ProfileExtensionsId getId() {
return this.id;
}
public void setId(ProfileExtensionsId id) {
this.id = id;
}
}
Quale SQL viene generato? Si prega inoltre di mostrare la mappatura e la tabella (se possibile semplificata). –