IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Création d'un objet et récupération id : java null exception [Data]


Sujet :

Spring Java

  1. #1
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut Création d'un objet et récupération id : java null exception
    Bonjour

    je voudrais effectuer un tas d'opérations à un objet crée mais l'id même est nul
    quand je l'affiche dans ma méthode et dans la base il s'incrémente normalement.
    voicil'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    java.lang.NullPointerException
    	com.proxymit.grh.service.interfImpl.VacationDAOImpl.calculateDura(VacationDAOImpl.java:1174)
    	com.proxymit.grh.service.interfImpl.VacationDAOImpl.createVacation(VacationDAOImpl.java:71)
    	com.proxymit.grh.web.VacationControllerAdd.addVacation(VacationControllerAdd.java:128)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	java.lang.reflect.Method.invoke(Method.java:597)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    et ma méthode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public Vacation createVacation(Vacation vacation) {
     
    		Employes employes = this.getCurrentEmployee();
    		vacation.setEmployes(employes);
    		String notification = "vacation not yet treated";
    		Double solde = 0.0;
    		vacation.setSolde(solde);
    		vacation.setNotification(notification);
    		Serializable vaca = hibernateTemplate.save(vacation);
    		System.out.println(vaca.toString());
    		 this.calculateDura(vacation.getIdvacation(), vacation.getSunsat());
    		return vacation;
     
    	}
    merci de m'aider SVP

  2. #2
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 962
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 962
    Par défaut
    Citation Envoyé par smiles Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    public Vacation createVacation(Vacation vacation) {
    
    		Employes employes = this.getCurrentEmployee();
    		vacation.setEmployes(employes);
    		String notification = "vacation not yet treated";
    		Double solde = 0.0;
    		vacation.setSolde(solde);
    		vacation.setNotification(notification);
    		Serializable vaca = hibernateTemplate.save(vacation);
    		System.out.println(vaca.toString());
    		 this.calculateDura(vacation.getIdvacation(), vacation.getSunsat());
    		return vacation;
    
    	}
    merci de m'aider SVP

  3. #3
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut
    ??? :-D

  4. #4
    Membre Expert
    Homme Profil pro
    Inscrit en
    Septembre 2006
    Messages
    2 962
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 962
    Par défaut
    Citation Envoyé par smiles Voir le message
    ??? :-D
    vaca ce n'est pas vacation…

    deux variables…

    c'est vaca qui est retourné par save() et qui contient le ID…

    vacation contient la version AVANT le save, sans ID donc…

  5. #5
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut
    pardon oui vous avez raison j'ai filé la méthode erronée

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    public void createVacation(Vacation vacation) {
    		Employes employes = this.getCurrentEmployee();
    		vacation.setEmployes(employes);
    		String notification = "vacation not yet treated";
    		Double solde = 0.0;
    		vacation.setSolde(solde);
    		vacation.setNotification(notification);
    		hibernateTemplate.save(vacation);
    		// System.out.println(vaca.toString());
     
    		Double dayOff = 0.0;
    		ArrayList<Date> dayList = this.listDayOff(this.dayOff1(), this
    				.dayOff2(), this.dayOff3(), this.dayOff4(), this.dayOff5(),
    				this.dayOff6(), this.dayOff7(), this.dayOff8(), this.dayOff9(),
    				this.dayOff10());
    		System.out.println(dayList);
    		Iterator it = dayList.iterator();
     
    		System.out.println(it);
    		// récupération de l'itérateur
     
    		while (it.hasNext()) {
     
    			// itération de la liste
     
    			Date o = (Date) it.next();
    			if ((o.after(vacation.getStartDate()) && o.before(vacation
    					.getEndDate())) == true) {
    				dayOff = dayOff + 1.0;
    			}
    			if (o.equals(vacation.getStartDate())
    					&& o.equals(vacation.getEndDate()) == true) {
    				dayOff = 1.0;
    			}
     
    		}
    		System.out.println("right");
    		System.out.println(dayOff);
     
    	this.calculateDura(vacation.getIdvacation(), vacation.getSunsat(),
    				vacation.getSolde(),dayOff);
     
    	}
     
     
    java.lang.NumberFormatException: null
    	java.lang.Integer.parseInt(Integer.java:417)
    	java.lang.Integer.parseInt(Integer.java:499)
    	com.proxymit.grh.web.FindEmployeeVacations.FindVacations(FindEmployeeVacations.java:108)

    c'est la mème erreur
    merci de m'aider

  6. #6
    Membre confirmé
    Inscrit en
    Février 2010
    Messages
    66
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 66
    Par défaut
    Bon j'ai fini par récréer toutes les méthodes dans cette méthode pour que ça marche

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 06/06/2012, 08h56
  2. Erreur Java null exception pointer dans un tMap
    Par easynoob dans le forum Développement de jobs
    Réponses: 2
    Dernier message: 12/05/2010, 10h42
  3. création dynamique d'objet, projet win32
    Par noinneh dans le forum MFC
    Réponses: 5
    Dernier message: 03/02/2005, 16h07
  4. [Reflexivite]création dynamique d'objet et Héritage
    Par norkius dans le forum API standards et tierces
    Réponses: 5
    Dernier message: 26/10/2004, 11h37
  5. Création d'un objet d'un form a l'autre
    Par Argonz dans le forum C++Builder
    Réponses: 12
    Dernier message: 03/03/2004, 10h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo