Récuperer les données d'une vue

Résolu/Fermé
rachida90 Messages postés 22 Date d'inscription mercredi 25 juillet 2012 Statut Membre Dernière intervention 26 mai 2013 - 26 mai 2013 à 03:50
choubaka Messages postés 39422 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 28 mars 2025 - 4 juin 2013 à 07:41
Bonsoir à tous,j'ai généré la classe persistante d'une vue avec hibernate et alors ce dernier pour cette vue 2 classes la première est la suivante
 
@Entity
@Table(name = "FORMULAIRE_ACCIDENT_TOTAL")
public class FormulaireAccidentTotal implements java.io.Serializable {
 
	private FormulaireAccidentTotalId id;
 
	public FormulaireAccidentTotal() {
	}
 
	public FormulaireAccidentTotal(FormulaireAccidentTotalId id) {
		this.id = id;
	}
 
	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "NOrdre", column = @Column(name = "N_ORDRE", nullable = false, precision = 22, scale = 0)),
			@AttributeOverride(name = "nomManoeuvreAccident", column = @Column(name = "NOM_MANOEUVRE_ACCIDENT")),
			@AttributeOverride(name = "libSurf", column = @Column(name = "LIB_SURF")),
			@AttributeOverride(name = "typeCollision", column = @Column(name = "TYPE_COLLISION")),
			@AttributeOverride(name = "libLum", column = @Column(name = "LIB_LUM")),
			@AttributeOverride(name = "nomTypeIntersection", column = @Column(name = "NOM_TYPE_INTERSECTION")),
			@AttributeOverride(name = "nomProfilLong", column = @Column(name = "NOM_PROFIL_LONG", nullable = false, length = 20)),
			@AttributeOverride(name = "nomTracePlan", column = @Column(name = "NOM_TRACE_PLAN")),
			@AttributeOverride(name = "nomAgent", column = @Column(name = "NOM_AGENT")),
			@AttributeOverride(name = "nomSignalisationVer", column = @Column(name = "NOM_SIGNALISATION_VER")),
			@AttributeOverride(name = "nomSignLum", column = @Column(name = "NOM_SIGN_LUM")),
			@AttributeOverride(name = "libIntemp", column = @Column(name = "LIB_INTEMP")),
			@AttributeOverride(name = "nomNbrVoie", column = @Column(name = "NOM_NBR_VOIE")),
			@AttributeOverride(name = "typeRegulation", column = @Column(name = "TYPE_REGULATION")),
			@AttributeOverride(name = "nomObstacleHeurte", column = @Column(name = "NOM_OBSTACLE_HEURTE")),
			@AttributeOverride(name = "typeCirculation", column = @Column(name = "TYPE_CIRCULATION")),
			@AttributeOverride(name = "nomPointChoc", column = @Column(name = "NOM_POINT_CHOC")),
			@AttributeOverride(name = "typeVoie", column = @Column(name = "TYPE_VOIE")),
			@AttributeOverride(name = "libChaus", column = @Column(name = "LIB_CHAUS")),
			@AttributeOverride(name = "dateHeure", column = @Column(name = "DATE_HEURE", length = 7)),
			@AttributeOverride(name = "villeCommune", column = @Column(name = "VILLE_COMMUNE")),
			@AttributeOverride(name = "totalTues", column = @Column(name = "TOTAL_TUES", precision = 22, scale = 0)),
			@AttributeOverride(name = "totalBlesses", column = @Column(name = "TOTAL_BLESSES", precision = 22, scale = 0)) })
	public FormulaireAccidentTotalId getId() {
		return this.id;
	}
 
	public void setId(FormulaireAccidentTotalId id) {
		this.id = id;
	}
 
}


et la 2eme est comme suite
 
package com.logisoft.classes;
 
// Generated 24 mai 2013 11:03:13 by Hibernate Tools 3.4.0.CR1
 
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embeddable;
 
/**
 * FormulaireAccidentTotalId generated by hbm2java
 */
@SuppressWarnings("serial")
@Embeddable
public class FormulaireAccidentTotalId implements java.io.Serializable {
 
	private BigDecimal NOrdre;
	private String nomManoeuvreAccident;
	private String libSurf;
	private String typeCollision;
	private String libLum;
	private String nomTypeIntersection;
	private String nomProfilLong;
	private String nomTracePlan;
	private String nomAgent;
	private String nomSignalisationVer;
	private String nomSignLum;
	private String libIntemp;
	private String nomNbrVoie;
	private String typeRegulation;
	private String nomObstacleHeurte;
	private String typeCirculation;
	private String nomPointChoc;
	private String typeVoie;
	private String libChaus;
	private Date dateHeure;
	private String villeCommune;
	private BigDecimal totalTues;
	private BigDecimal totalBlesses;
 
	public FormulaireAccidentTotalId() {
	}
 
	public FormulaireAccidentTotalId(BigDecimal NOrdre, String nomProfilLong) {
		this.NOrdre = NOrdre;
		this.nomProfilLong = nomProfilLong;
	}
 
	public FormulaireAccidentTotalId(BigDecimal NOrdre,
			String nomManoeuvreAccident, String libSurf, String typeCollision,
			String libLum, String nomTypeIntersection, String nomProfilLong,
			String nomTracePlan, String nomAgent, String nomSignalisationVer,
			String nomSignLum, String libIntemp, String nomNbrVoie,
			String typeRegulation, String nomObstacleHeurte, String typeCirculation,
			String nomPointChoc, String typeVoie, String libChaus, Date dateHeure,
			String villeCommune, BigDecimal totalTues, BigDecimal totalBlesses) {
		this.NOrdre = NOrdre;
		this.nomManoeuvreAccident = nomManoeuvreAccident;
		this.libSurf = libSurf;
		this.typeCollision = typeCollision;
		this.libLum = libLum;
		this.nomTypeIntersection = nomTypeIntersection;
		this.nomProfilLong = nomProfilLong;
		this.nomTracePlan = nomTracePlan;
		this.nomAgent = nomAgent;
		this.nomSignalisationVer = nomSignalisationVer;
		this.nomSignLum = nomSignLum;
		this.libIntemp = libIntemp;
		this.nomNbrVoie = nomNbrVoie;
		this.typeRegulation = typeRegulation;
		this.nomObstacleHeurte = nomObstacleHeurte;
		this.typeCirculation = typeCirculation;
		this.nomPointChoc = nomPointChoc;
		this.typeVoie = typeVoie;
		this.libChaus = libChaus;
		this.dateHeure = dateHeure;
		this.villeCommune = villeCommune;
		this.totalTues = totalTues;
		this.totalBlesses = totalBlesses;
	}
 
	@Column(name = "N_ORDRE", nullable = false, precision = 22, scale = 0)
	public BigDecimal getNOrdre() {
		return this.NOrdre;
	}
 
	public void setNOrdre(BigDecimal NOrdre) {
		this.NOrdre = NOrdre;
	}
 
	@Column(name = "NOM_MANOEUVRE_ACCIDENT")
	public String getNomManoeuvreAccident() {
		return this.nomManoeuvreAccident;
	}
 
	public void setNomManoeuvreAccident(String nomManoeuvreAccident) {
		this.nomManoeuvreAccident = nomManoeuvreAccident;
	}
 
	@Column(name = "LIB_SURF")
	public String getLibSurf() {
		return this.libSurf;
	}
 
	public void setLibSurf(String libSurf) {
		this.libSurf = libSurf;
	}
 
	@Column(name = "TYPE_COLLISION")
	public String getTypeCollision() {
		return this.typeCollision;
	}
 
	public void setTypeCollision(String typeCollision) {
		this.typeCollision = typeCollision;
	}
 
	@Column(name = "LIB_LUM")
	public String getLibLum() {
		return this.libLum;
	}
 
	public void setLibLum(String libLum) {
		this.libLum = libLum;
	}
 
	@Column(name = "NOM_TYPE_INTERSECTION")
	public String getNomTypeIntersection() {
		return this.nomTypeIntersection;
	}
 
	public void setNomTypeIntersection(String nomTypeIntersection) {
		this.nomTypeIntersection = nomTypeIntersection;
	}
 
	@Column(name = "NOM_PROFIL_LONG", nullable = false, length = 20)
	public String getNomProfilLong() {
		return this.nomProfilLong;
	}
 
	public void setNomProfilLong(String nomProfilLong) {
		this.nomProfilLong = nomProfilLong;
	}
 
	@Column(name = "NOM_TRACE_PLAN")
	public String getNomTracePlan() {
		return this.nomTracePlan;
	}
 
	public void setNomTracePlan(String nomTracePlan) {
		this.nomTracePlan = nomTracePlan;
	}
 
	@Column(name = "NOM_AGENT")
	public String getNomAgent() {
		return this.nomAgent;
	}
 
	public void setNomAgent(String nomAgent) {
		this.nomAgent = nomAgent;
	}
 
	@Column(name = "NOM_SIGNALISATION_VER")
	public String getNomSignalisationVer() {
		return this.nomSignalisationVer;
	}
 
	public void setNomSignalisationVer(String nomSignalisationVer) {
		this.nomSignalisationVer = nomSignalisationVer;
	}
 
	@Column(name = "NOM_SIGN_LUM")
	public String getNomSignLum() {
		return this.nomSignLum;
	}
 
	public void setNomSignLum(String nomSignLum) {
		this.nomSignLum = nomSignLum;
	}
 
	@Column(name = "LIB_INTEMP")
	public String getLibIntemp() {
		return this.libIntemp;
	}
 
	public void setLibIntemp(String libIntemp) {
		this.libIntemp = libIntemp;
	}
 
	@Column(name = "NOM_NBR_VOIE")
	public String getNomNbrVoie() {
		return this.nomNbrVoie;
	}
 
	public void setNomNbrVoie(String nomNbrVoie) {
		this.nomNbrVoie = nomNbrVoie;
	}
 
	@Column(name = "TYPE_REGULATION")
	public String getTypeRegulation() {
		return this.typeRegulation;
	}
 
	public void setTypeRegulation(String typeRegulation) {
		this.typeRegulation = typeRegulation;
	}
 
	@Column(name = "NOM_OBSTACLE_HEURTE")
	public String getNomObstacleHeurte() {
		return this.nomObstacleHeurte;
	}
 
	public void setNomObstacleHeurte(String nomObstacleHeurte) {
		this.nomObstacleHeurte = nomObstacleHeurte;
	}
 
	@Column(name = "TYPE_CIRCULATION")
	public String getTypeCirculation() {
		return this.typeCirculation;
	}
 
	public void setTypeCirculation(String typeCirculation) {
		this.typeCirculation = typeCirculation;
	}
 
	@Column(name = "NOM_POINT_CHOC")
	public String getNomPointChoc() {
		return this.nomPointChoc;
	}
 
	public void setNomPointChoc(String nomPointChoc) {
		this.nomPointChoc = nomPointChoc;
	}
 
	@Column(name = "TYPE_VOIE")
	public String getTypeVoie() {
		return this.typeVoie;
	}
 
	public void setTypeVoie(String typeVoie) {
		this.typeVoie = typeVoie;
	}
 
	@Column(name = "LIB_CHAUS")
	public String getLibChaus() {
		return this.libChaus;
	}
 
	public void setLibChaus(String libChaus) {
		this.libChaus = libChaus;
	}
 
	@Column(name = "DATE_HEURE", length = 7)
	public Date getDateHeure() {
		return this.dateHeure;
	}
 
	public void setDateHeure(Date dateHeure) {
		this.dateHeure = dateHeure;
	}
 
	@Column(name = "VILLE_COMMUNE")
	public String getVilleCommune() {
		return this.villeCommune;
	}
 
	public void setVilleCommune(String villeCommune) {
		this.villeCommune = villeCommune;
	}
 
	@Column(name = "TOTAL_TUES", precision = 22, scale = 0)
	public BigDecimal getTotalTues() {
		return this.totalTues;
	}
 
	public void setTotalTues(BigDecimal totalTues) {
		this.totalTues = totalTues;
	}
 
	@Column(name = "TOTAL_BLESSES", precision = 22, scale = 0)
	public BigDecimal getTotalBlesses() {
		return this.totalBlesses;
	}
 
	public void setTotalBlesses(BigDecimal totalBlesses) {
		this.totalBlesses = totalBlesses;
	}
 
	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof FormulaireAccidentTotalId))
			return false;
		FormulaireAccidentTotalId castOther = (FormulaireAccidentTotalId) other;
 
		return ((this.getNOrdre() == castOther.getNOrdre()) || (this
				.getNOrdre() != null && castOther.getNOrdre() != null && this
				.getNOrdre().equals(castOther.getNOrdre())))
				&& ((this.getNomManoeuvreAccident() == castOther
						.getNomManoeuvreAccident()) || (this
						.getNomManoeuvreAccident() != null
						&& castOther.getNomManoeuvreAccident() != null && this
						.getNomManoeuvreAccident().equals(
								castOther.getNomManoeuvreAccident())))
				&& ((this.getLibSurf() == castOther.getLibSurf()) || (this
						.getLibSurf() != null && castOther.getLibSurf() != null && this
						.getLibSurf().equals(castOther.getLibSurf())))
				&& ((this.getTypeCollision() == castOther.getTypeCollision()) || (this
						.getTypeCollision() != null
						&& castOther.getTypeCollision() != null && this
						.getTypeCollision()
						.equals(castOther.getTypeCollision())))
				&& ((this.getLibLum() == castOther.getLibLum()) || (this
						.getLibLum() != null && castOther.getLibLum() != null && this
						.getLibLum().equals(castOther.getLibLum())))
				&& ((this.getNomTypeIntersection() == castOther
						.getNomTypeIntersection()) || (this
						.getNomTypeIntersection() != null
						&& castOther.getNomTypeIntersection() != null && this
						.getNomTypeIntersection().equals(
								castOther.getNomTypeIntersection())))
				&& ((this.getNomProfilLong() == castOther.getNomProfilLong()) || (this
						.getNomProfilLong() != null
						&& castOther.getNomProfilLong() != null && this
						.getNomProfilLong()
						.equals(castOther.getNomProfilLong())))
				&& ((this.getNomTracePlan() == castOther.getNomTracePlan()) || (this
						.getNomTracePlan() != null
						&& castOther.getNomTracePlan() != null && this
						.getNomTracePlan().equals(castOther.getNomTracePlan())))
				&& ((this.getNomAgent() == castOther.getNomAgent()) || (this
						.getNomAgent() != null
						&& castOther.getNomAgent() != null && this
						.getNomAgent().equals(castOther.getNomAgent())))
				&& ((this.getNomSignalisationVer() == castOther
						.getNomSignalisationVer()) || (this
						.getNomSignalisationVer() != null
						&& castOther.getNomSignalisationVer() != null && this
						.getNomSignalisationVer().equals(
								castOther.getNomSignalisationVer())))
				&& ((this.getNomSignLum() == castOther.getNomSignLum()) || (this
						.getNomSignLum() != null
						&& castOther.getNomSignLum() != null && this
						.getNomSignLum().equals(castOther.getNomSignLum())))
				&& ((this.getLibIntemp() == castOther.getLibIntemp()) || (this
						.getLibIntemp() != null
						&& castOther.getLibIntemp() != null && this
						.getLibIntemp().equals(castOther.getLibIntemp())))
				&& ((this.getNomNbrVoie() == castOther.getNomNbrVoie()) || (this
						.getNomNbrVoie() != null
						&& castOther.getNomNbrVoie() != null && this
						.getNomNbrVoie().equals(castOther.getNomNbrVoie())))
				&& ((this.getTypeRegulation() == castOther.getTypeRegulation()) || (this
						.getTypeRegulation() != null
						&& castOther.getTypeRegulation() != null && this
						.getTypeRegulation().equals(
								castOther.getTypeRegulation())))
				&& ((this.getNomObstacleHeurte() == castOther
						.getNomObstacleHeurte()) || (this
						.getNomObstacleHeurte() != null
						&& castOther.getNomObstacleHeurte() != null && this
						.getNomObstacleHeurte().equals(
								castOther.getNomObstacleHeurte())))
				&& ((this.getTypeCirculation() == castOther
						.getTypeCirculation()) || (this.getTypeCirculation() != null
						&& castOther.getTypeCirculation() != null && this
						.getTypeCirculation().equals(
								castOther.getTypeCirculation())))
				&& ((this.getNomPointChoc() == castOther.getNomPointChoc()) || (this
						.getNomPointChoc() != null
						&& castOther.getNomPointChoc() != null && this
						.getNomPointChoc().equals(castOther.getNomPointChoc())))
				&& ((this.getTypeVoie() == castOther.getTypeVoie()) || (this
						.getTypeVoie() != null
						&& castOther.getTypeVoie() != null && this
						.getTypeVoie().equals(castOther.getTypeVoie())))
				&& ((this.getLibChaus() == castOther.getLibChaus()) || (this
						.getLibChaus() != null
						&& castOther.getLibChaus() != null && this
						.getLibChaus().equals(castOther.getLibChaus())))
				&& ((this.getDateHeure() == castOther.getDateHeure()) || (this
						.getDateHeure() != null
						&& castOther.getDateHeure() != null && this
						.getDateHeure().equals(castOther.getDateHeure())))
				&& ((this.getVilleCommune() == castOther.getVilleCommune()) || (this
						.getVilleCommune() != null
						&& castOther.getVilleCommune() != null && this
						.getVilleCommune().equals(castOther.getVilleCommune())))
				&& ((this.getTotalTues() == castOther.getTotalTues()) || (this
						.getTotalTues() != null
						&& castOther.getTotalTues() != null && this
						.getTotalTues().equals(castOther.getTotalTues())))
				&& ((this.getTotalBlesses() == castOther.getTotalBlesses()) || (this
						.getTotalBlesses() != null
						&& castOther.getTotalBlesses() != null && this
						.getTotalBlesses().equals(castOther.getTotalBlesses())));
	}
 
	public int hashCode() {
		int result = 17;
 
		result = 37 * result
				+ (getNOrdre() == null ? 0 : this.getNOrdre().hashCode());
		result = 37
				* result
				+ (getNomManoeuvreAccident() == null ? 0 : this
						.getNomManoeuvreAccident().hashCode());
		result = 37 * result
				+ (getLibSurf() == null ? 0 : this.getLibSurf().hashCode());
		result = 37
				* result
				+ (getTypeCollision() == null ? 0 : this.getTypeCollision()
						.hashCode());
		result = 37 * result
				+ (getLibLum() == null ? 0 : this.getLibLum().hashCode());
		result = 37
				* result
				+ (getNomTypeIntersection() == null ? 0 : this
						.getNomTypeIntersection().hashCode());
		result = 37
				* result
				+ (getNomProfilLong() == null ? 0 : this.getNomProfilLong()
						.hashCode());
		result = 37
				* result
				+ (getNomTracePlan() == null ? 0 : this.getNomTracePlan()
						.hashCode());
		result = 37 * result
				+ (getNomAgent() == null ? 0 : this.getNomAgent().hashCode());
		result = 37
				* result
				+ (getNomSignalisationVer() == null ? 0 : this
						.getNomSignalisationVer().hashCode());
		result = 37
				* result
				+ (getNomSignLum() == null ? 0 : this.getNomSignLum()
						.hashCode());
		result = 37 * result
				+ (getLibIntemp() == null ? 0 : this.getLibIntemp().hashCode());
		result = 37
				* result
				+ (getNomNbrVoie() == null ? 0 : this.getNomNbrVoie()
						.hashCode());
		result = 37
				* result
				+ (getTypeRegulation() == null ? 0 : this.getTypeRegulation()
						.hashCode());
		result = 37
				* result
				+ (getNomObstacleHeurte() == null ? 0 : this
						.getNomObstacleHeurte().hashCode());
		result = 37
				* result
				+ (getTypeCirculation() == null ? 0 : this.getTypeCirculation()
						.hashCode());
		result = 37
				* result
				+ (getNomPointChoc() == null ? 0 : this.getNomPointChoc()
						.hashCode());
		result = 37 * result
				+ (getTypeVoie() == null ? 0 : this.getTypeVoie().hashCode());
		result = 37 * result
				+ (getLibChaus() == null ? 0 : this.getLibChaus().hashCode());
		result = 37 * result
				+ (getDateHeure() == null ? 0 : this.getDateHeure().hashCode());
		result = 37
				* result
				+ (getVilleCommune() == null ? 0 : this.getVilleCommune()
						.hashCode());
		result = 37 * result
				+ (getTotalTues() == null ? 0 : this.getTotalTues().hashCode());
		result = 37
				* result
				+ (getTotalBlesses() == null ? 0 : this.getTotalBlesses()
						.hashCode());
		return result;
	}
 
}

j'ai crée une classe service pour la manipulation des données de la vue,moi je teste maintenant la récupération des données seulement
 
package com.logisoft.service;
 
import java.math.BigDecimal;
import java.util.List;
 
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.logisoft.classes.FormulaireAccident;
import com.logisoft.classes.FormulaireAccidentTotal;
import com.logisoft.classes.FormulaireAccidentTotal;
 
@Service("formulaireAccidentTotalService")
@Transactional
public class FormulaireAccidentTotalServiceImpl implements
		FormulaireAccidentTotalService {
	@Autowired
	private SessionFactory sessionFactory;
	@SuppressWarnings("unchecked")
	@Override
	public List<FormulaireAccidentTotal> findAll() {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from FormulaireAccidentTotal").list();
 
	}
 
	@Override
	public FormulaireAccidentTotal findById(String nordre) {
		// TODO Auto-generated method stub
		return null;
	}
 
	@Override
	public void save(FormulaireAccidentTotal formulaire) {
		// TODO Auto-generated method stub
 
	}
 
 
 
}

à l'aide de jUnit j'essaye d'afficher les elements de ma vue mais ca me donne toujours des erreurs,
 
package com.logisoft.service;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
 
import java.math.BigDecimal;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;
 
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
 
import com.logisoft.classes.Agent;
import com.logisoft.classes.Conducteur;
import com.logisoft.classes.FormulaireAccidentTotal;
import com.logisoft.classes.FormulaireAccidentTotal;
import com.logisoft.classes.ManoeuvrePieton;
import com.logisoft.classes.SignalisationLumineuse;
import com.logisoft.classes.FormulaireAccident;
import com.logisoft.classes.GendarmerieRoyale;
import com.logisoft.classes.SureteNationale;
 
public class AgentServiceTest {
	private static ClassPathXmlApplicationContext context;
	private static FormulaireAccidentTotalService formulaireAccidentTotalService;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		context=new ClassPathXmlApplicationContext("application-contexte.xml");
		formulaireAccidentTotalService=(FormulaireAccidentTotalService) context.getBean("formulaireAccidentTotalService");
	}
 
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		context.close();
	}
		@Test
	public void testFindAll() {
		List<FormulaireAccidentTotal> allManoeuvrePieton = formulaireAccidentTotalService.findAll();
		assertNotNull(allManoeuvrePieton);
		assertTrue(allManoeuvrePieton.size()>0);
		System.out.println(allManoeuvrePieton.size());
		System.out.println(allManoeuvrePieton.get(0).getId().getLibChaus());
	System.out.println(allManoeuvrePieton.get(1).getNomFaute()+" "+allManoeuvrePieton.get(1).getFaute());
	}
}

pour le 1er println il m'affiche 1 ce qui est juste ma vue a seulement un enregistrement alors que pour le 2 eme affichage il me donne une erreur java.Lang.NullPointerException

1 réponse

choubaka Messages postés 39422 Date d'inscription jeudi 4 avril 2002 Statut Modérateur Dernière intervention 28 mars 2025 2 104
4 juin 2013 à 07:41
Bonjour

Il faut remonter le code d'erreur et voir quel objet n'a pas été instancié...
code d'erreur défini pour ce type de cas..
0