baliukas wrote:
Quote:
public class ComposanteDTO {
Integer composanteId;
String composanteLibelle;
Integer etablissementId;
it must be EtablissementDTO, if you map it as "many-to-one"
Thanks again, but I still have one more problem to resolve :
Heres the code :
Code:
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
ComposanteDTO composante = (ComposanteDTO) session.get(ComposanteDTO.class, primaryKey);
System.out.println("Id " + composante.getComposanteId() + " Nom "
+ composante.getComposanteLibelle());
tx.commit();
HibernateUtil.closeSession();
And the exception (the mappings haven't changed) :
Quote:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3120)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:812)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:782)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1375)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at cri.univrennes1.fr.accesdonnees.services.ComposanteService.listeComposantes(ComposanteService.java:106)
at cri.univrennes1.fr.hibernate.TestClient.main(TestClient.java:26)
and the classes :
Code:
package cri.univrennes1.fr.accesdonnees;
public class ComposanteDTO {
Integer composanteId;
String composanteLibelle;
EtablissementDTO etablissement;
public Integer getComposanteId() {
return composanteId;
}
public void setComposanteId(Integer composanteId) {
this.composanteId = composanteId;
}
public String getComposanteLibelle() {
return composanteLibelle;
}
public void setComposanteLibelle(String composanteLibelle) {
this.composanteLibelle = composanteLibelle;
}
public EtablissementDTO getEtablissement() {
return etablissement;
}
public void setEtablissement(EtablissementDTO etablissement) {
this.etablissement = etablissement;
}
}
Code:
package cri.univrennes1.fr.accesdonnees;
import java.util.Set;
public class EtablissementDTO {
private Integer etablissementId;
private String etablissementLibelle;
private Set composantes;
public Integer getEtablissementId() {
return etablissementId;
}
public void setEtablissementId(Integer etablissementId) {
this.etablissementId = etablissementId;
}
public String getEtablissementLibelle() {
return etablissementLibelle;
}
public void setEtablissementLibelle(String etablissementLibelle) {
this.etablissementLibelle = etablissementLibelle;
}
public Set getComposantes() {
return composantes;
}
public void setComposantes(Set composantes) {
this.composantes = composantes;
}
}