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

JPA Java Discussion :

q.getResultList() -> liste d'elements null


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de snipes
    Inscrit en
    Septembre 2004
    Messages
    547
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 547
    Par défaut q.getResultList() -> liste d'elements null
    bonjour tout le monde,

    j'ai mi en place une methode qui marchait tres bien. Depuis que j'ai modifié mes entités la liste qui est retourné contient que des elements "null" mais contient bien le nombre de ligne correspondant au resultat

    ma methode :
    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
    @SuppressWarnings("unchecked")
    	public List<Demande> demandeDuJour(Integer iduniteintervenant,Integer idintervenant,ProfilRessource profil) {
     
    		StringBuffer query = new StringBuffer();
     
    		query.append("Select distinct d from Demande d where" +				
    				" d.datedebutprevue <= CURRENT_DATE and d.etat <> :etat  ");
     
    		if ((!profil.equals(ProfilRessource.ADMINISTRATEUR)) && (!profil.equals(ProfilRessource.CONSULTANT))) {
    			query.append("and (d.unitetravail.idunitetravail = :iduniteintervenant or  d.intervenant.idressource = :idintervenant) ");
    		}
    		query.append("order by d.datedebutprevue desc,d.iddemande desc ");
     
    		Query q = em.createQuery(query.toString());		
    		q.setParameter("etat",Demande.Etat.TERMINEE);	
     
    		if ((!profil.equals(ProfilRessource.ADMINISTRATEUR)) && (!profil.equals(ProfilRessource.CONSULTANT))) {	
    			if(iduniteintervenant!=null){
    				q.setParameter("iduniteintervenant", iduniteintervenant);
    				q.setParameter("idintervenant", null);
    			}
    			else{
    				q.setParameter("iduniteintervenant", null);
    				q.setParameter("idintervenant", idintervenant);
    			}
    		}
    		return q.getResultList();
     
    	}
    Mon entite Demande :
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    @Entity
    @NamedQueries( {
    		@NamedQuery(name = "countDemande", query = "Select count(*) from Demande"),
    		@NamedQuery(name = "findAllDemande", query = "Select d from  Demande d order by d.libelle asc") })
    public class Demande extends Travail implements java.io.Serializable{
     
    	// ----------------------------------------------------------------------------
    	// CONSTANTES
    	// ----------------------------------------------------------------------------
    		private static final long serialVersionUID = 1L;
     
    		//LISTE DES ORIGINES POSSIBLES D'UNE Travail
    		public enum Origine {
    			A1,A2,A3
    		};
     
    	// ----------------------------------------------------------------------------
    	// PROPRIETES
    	// ----------------------------------------------------------------------------	
     
    		private Integer iddemande;
    		private Origine origine;
    		private Activite activite = new Activite();
    		private boolean decompose=false;
     
    	// ----------------------------------------------------------------------------
    	// METHODES PUBLIQUES
    	// ----------------------------------------------------------------------------
    		public Demande() {
    			super();
    			// TODO Raccord de constructeur auto-généré
    		}
     
    		@Id
    		@GeneratedValue(strategy=GenerationType.AUTO)
    		@Column(name="iddemande")
    		public Integer getIddemande() {
    			return iddemande;
    		}
     
    		@Enumerated(value = EnumType.STRING)
    		public Origine getOrigine() {
    			return origine;
    		}
     
    		public void setOrigine(Origine origine) {
    			this.origine = origine;
    		}
     
    		public boolean isDecompose() {
    			return decompose;
    		}
     
    		public void setDecompose(boolean decompose) {
    			this.decompose = decompose;
    		}
     
    		public void setIddemande(Integer iddemande) {
    			this.iddemande = iddemande;
    		}
     
    		@ManyToOne
    		@JoinColumn(name = "activite")
    		public Activite getActivite() {
    			return activite;
    		}
     
    		public void setActivite(Activite activite) {
    			this.activite = activite;
    		}
     
     
    	// ----------------------------------------------------------------------------
    	// PROPRIETES CALCULEES (TRANSIENTES)
    	// ----------------------------------------------------------------------------
     
    		@Transient
    		public String getActiviteAsString() {
    			return activite!=null?activite.getLibelle():"";
    		}
     
    }
    Mon entité travail
    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
     
    @MappedSuperclass
    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
    public abstract class Travail implements java.io.Serializable{
     
    	// ----------------------------------------------------------------------------
    	// CONSTANTES
    	// ----------------------------------------------------------------------------
    		private static final long serialVersionUID = 1L;
     
    		// LISTE DES ETAT D'UNE DEMANDE
    		public enum Etat {
    			A_REALISER, EN_COURS, TERMINEE, REJETEE, PLANIFIEE, EN_ATTENTE
    		};		
     
    	// ----------------------------------------------------------------------------
    	// PROPRIETES
    	// ----------------------------------------------------------------------------	
     
    		protected String libelle;
    		protected String description;
    		protected Date datecreation;
    		protected Date datefinreel;
    		protected String commentaire;
    		protected Date dateder_maj;
    		protected Date datedebutprevue;		
    		protected Date datefinprevue;
    		protected Date dateplannification;
    		protected Date datepec; //pec : pris en charge
    		protected Ressource demandeur;		
    		protected Etat etat;
    		protected Collection<Fichier> fichiers= new ArrayList<Fichier>();
    		protected Priorite priorite;
    		protected String emailcc;
     
    		//Prise en charge de la Demande
    		protected Ressource responsablepec;
     
    		//Demande attribué a :
    		protected Ressource intervenant = new Ressource();
    		protected UniteTravail unitetravail = new UniteTravail();
     
     
     
    	// ----------------------------------------------------------------------------
    	// METHODES PUBLIQUES
    	// ----------------------------------------------------------------------------
     
    		@Column(length=500)
    		public String getCommentaire() {
    			return commentaire;
    		}
     
    		public void setCommentaire(String commentaire) {
    			this.commentaire = commentaire;
    		}
     
    		@Temporal(TemporalType.DATE)
    		@Column(nullable=false)
    		public Date getDatecreation() {
    			return datecreation;
    		}
     
    		public void setDatecreation(Date datecreation) {
    			this.datecreation = datecreation;
    		}	
     
    		@Temporal(TemporalType.DATE)
    		public Date getDatefinreel() {
    			return datefinreel;
    		}
     
    		public void setDatefinreel(Date datefinreel) {
    			this.datefinreel = datefinreel;
    		}
     
    		@Temporal(TemporalType.DATE)
    		public Date getDateder_maj() {
    			return dateder_maj;
    		}
     
    		public void setDateder_maj(Date dateder_maj) {
    			this.dateder_maj = dateder_maj;
    		}
     
    		@Column(length=1000,nullable=false)
    		public String getDescription() {
    			return description;
    		}
     
    		public void setDescription(String description) {
    			this.description = description;
    		}
     
    		@Column(length=200,nullable=false)
    		public String getLibelle() {
    			return libelle;
    		}
     
    		public void setLibelle(String libelle) {
    			this.libelle = libelle;
    		}
     
    		public Travail() {
    			super();
    			// TODO Raccord de constructeur auto-généré
    		}
     
    		@ManyToOne
    		@JoinColumn(name="iddemandeur")
    		public Ressource getDemandeur() {
    			return demandeur;
    		}
     
    		public void setDemandeur(Ressource demandeur) {
    			this.demandeur = demandeur;
    		}
     
    		@ManyToOne
    		@JoinColumn(name = "intervenant")
    		public Ressource getIntervenant() {
    			return intervenant;
    		}
     
    		public void setIntervenant(Ressource intervenant) {
    			this.intervenant = intervenant;
    		}
     
    		@ManyToOne
    		@JoinColumn(name = "unitetravail")
    		public UniteTravail getUnitetravail() {
    			return unitetravail;
    		}
     
    		public void setUnitetravail(UniteTravail unitetravail) {
    			this.unitetravail = unitetravail;
    		}
     
    		@Enumerated(value = EnumType.ORDINAL)
    		public Etat getEtat() {
    			return etat;
    		}
     
    		public void setEtat(Etat etat) {
    			this.etat = etat;
    		}
     
    		@Temporal(TemporalType.DATE)
    		public Date getDatedebutprevue() {
    			return datedebutprevue;
    		}
     
    		public void setDatedebutprevue(Date datedebutprevue) {
    			this.datedebutprevue = datedebutprevue;
    		}
     
    		@Temporal(TemporalType.DATE)
    		public Date getDatefinprevue() {
    			return datefinprevue;
    		}
     
    		public void setDatefinprevue(Date datefinprevue) {
    			this.datefinprevue = datefinprevue;
    		}
     
    		@ManyToOne
    		@JoinColumn(name = "responsable")
    		public Ressource getResponsablepec() {
    			return responsablepec;
    		}
     
    		public void setResponsablepec(Ressource responsablepec) {
    			this.responsablepec = responsablepec;
    		}
     
    	// ----------------------------------------------------------------------------
    	// PROPRIETES CALCULEES (TRANSIENTES)
    	// ----------------------------------------------------------------------------
    		@Transient
    		public String getEtatAsString() {
    			return getEtatAsString(etat);
    		}
     
    		@Transient
    		public static String getEtatAsString(Etat etat) {
    			if (etat.equals(null))
    				return "";
    			else if (etat.equals(Etat.A_REALISER))
    				return "A Realiser";
    			else if (etat.equals(Etat.EN_COURS))
    				return "En Cours";
    			else if (etat.equals(Etat.REJETEE))
    				return "Rejetée";			
    			else if (etat.equals(Etat.PLANIFIEE))
    				return "Planifiée";
    			else if (etat.equals(Etat.EN_ATTENTE))
    				return "En Attente";
    			else if (etat.equals(Etat.TERMINEE))
    				return "Réalisée";
    			return "";
    		}
     
    		@Transient
    		public static Etat getEtatAsObject(int value) {
    			for (int index = 0; index < Travail.Etat.values().length; index++) {
    				if (value == Travail.Etat.values()[index].ordinal())
    					return Travail.Etat.values()[index];
    			}
    			return null;
    		}
     
    		@Transient
    		public String getDemandeurAsString() {
    			return demandeur!=null?demandeur.getNomPrenomsAsString():"????";
    		}
     
    		/**
                     * Renvoie le statut de la demande
                     * 
                     * @return
                     */
    		@Transient
    		public String getStatutAsShortString() {
    			if (etat==null)
    				return "";
    			else if (etat.equals(Etat.EN_COURS))
    				return "En cours";
    			else if (etat.equals(Etat.REJETEE))
    				return "Rejetée";
    			else if (etat.equals(Etat.TERMINEE))
    				return "Réalisée";
    			else if (etat.equals(Etat.PLANIFIEE))
    				return "Planifiée";
    			else if (etat.equals(Etat.A_REALISER))
    				return "A Réaliser";
    			else if (etat.equals(Etat.EN_ATTENTE))
    				return "En Attente";
    			return "";
    		}
     
    		@Transient
    		public boolean isPlanifiee() {
    			return etat!=null && etat.equals(Etat.PLANIFIEE)?true:false;
    		}
     
    		@Transient
    		public String getIntervenantAsString() {
    			return intervenant!=null?intervenant.getNomPrenomsAsString():"";
    		}
     
    		@Transient
    		public String getUniteTravailAsString() {
    			return unitetravail!=null?unitetravail.getLibelle():"";
    		}
     
    		@Enumerated(value = EnumType.ORDINAL)
    		public Priorite getPriorite() {
    			return priorite;
    		}
     
    		public void setPriorite(Priorite priorite) {
    			this.priorite = priorite;
    		}
     
    		/**
                     * Renvoie la priorite de la demande
                     * 
                     * @return
                     */
    		@Transient
    		public String getPrioriteAsShortString() {
    			if (priorite==null)
    				return "";
    			else if (priorite.equals(Priorite.NORMAL)) {
    				return "Normal";
    			}
    			else if (priorite.equals(Priorite.URGENT))
    				return "Urgent";
    			return "";
    		}
     
    		@OneToMany(mappedBy="demande",cascade = {CascadeType.ALL})		
    		public Collection<Fichier> getFichiers() {
    			return fichiers;
    		}
     
    		public void setFichiers(Collection<Fichier> fichiers) {
    			this.fichiers = fichiers;
    		}
     
    		@Temporal(TemporalType.DATE)
    		public Date getDatepec() {
    			return datepec;
    		}
     
    		public void setDatepec(Date datepec) {
    			this.datepec = datepec;
    		}
     
    		public String getEmailcc() {
    			return emailcc;
    		}
     
    		public void setEmailcc(String emailcc) {
    			this.emailcc = emailcc;
    		}
     
    		@Temporal(TemporalType.DATE)
    		public Date getDateplannification() {
    			return dateplannification;
    		}
     
    		public void setDateplannification(Date dateplannification) {
    			this.dateplannification = dateplannification;
    		}
     
    }
    Aucun message d'erreur est retourné
    Quelqu'un aurait une tite idée sur l'origine du probleme ?

  2. #2
    Membre éclairé Avatar de snipes
    Inscrit en
    Septembre 2004
    Messages
    547
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 547
    Par défaut
    L'insertion d'information marche sans probleme par contre, je retrouve bien mes données dans la base
    C'est apparement a la lecture que ca pose probleme

  3. #3
    Membre averti
    Inscrit en
    Février 2008
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 18
    Par défaut
    Salut
    qu'est ce que tu as modifié?

  4. #4
    Membre éclairé Avatar de snipes
    Inscrit en
    Septembre 2004
    Messages
    547
    Détails du profil
    Informations forums :
    Inscription : Septembre 2004
    Messages : 547
    Par défaut
    Salut,
    au depart je n'avais pas la classe abstraite Travail, tous les attributs(ainsi que les getter setter et enum) se trouvaient directement dans Demande

  5. #5
    Membre averti
    Inscrit en
    Février 2008
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 18
    Par défaut
    tu peux deja commencer par virer cette ligne :
    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
    parce que un MappedSuperClass ne va requiert pas cela
    et reessaie

  6. #6
    Nouveau candidat au Club
    Inscrit en
    Avril 2003
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 2
    Par défaut
    Je viens d'avoir ce problème, cad une liste d'élément null retournée par un getResultList().

    Dans mon cas l'erreur venait de l'ID qui était composé, et dont l'un des éléments était null.

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

    Informations forums :
    Inscription : Septembre 2006
    Messages : 2 963
    Par défaut
    Citation Envoyé par snipes Voir le message
    Aucun message d'erreur est retourné
    Quelqu'un aurait une tite idée sur l'origine du probleme ?
    de mémoire, tous les exemples de @MappedSuperclass me semblent mettre l'@Id dans la @MappedSuperclass…

    ce qui semble assez logique : toutes les sous-classes éventuelles de la @MappedSuperclass doivent partager la même stratégie de primary key…

Discussions similaires

  1. Réponses: 2
    Dernier message: 07/11/2006, 15h43
  2. Itération sur une liste d'éléments
    Par anitshka dans le forum Prolog
    Réponses: 3
    Dernier message: 05/07/2006, 22h49
  3. Réponses: 3
    Dernier message: 11/05/2006, 00h27
  4. Réponses: 7
    Dernier message: 21/03/2006, 23h01
  5. Transformer elements NULL par 0
    Par Carter dans le forum Langage SQL
    Réponses: 3
    Dernier message: 07/02/2006, 15h34

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