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

JSF Java Discussion :

Problème annotation Hibernate


Sujet :

JSF Java

  1. #1
    Membre confirmé
    Inscrit en
    Juillet 2007
    Messages
    64
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 64
    Par défaut Problème annotation Hibernate
    Bonjour;
    je développe une application web (JSF+primefaces+Hibernate+Oracle11g)
    j'ai trois tables: Fonctionnalite, Profile et ProfileFonctionnalite.
    elles sont mappées de la façon suivate:
    Fonctionnalite
    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
    package winservices.mapping;
     
    import java.io.Serializable;
     
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
     
    import org.hibernate.annotations.Proxy;
     
     
     
    @Entity
    @Table(name="TBL_FONCTIONALITE")
    public class Fonctionnalite implements Serializable{
     
    	private static final long serialVersionUID = 1L;
     
    	private String codeFonctionalite;
    	private String fonctionalite;
    	private Fonctionnalite parent;
    	private String lien;
    	private String methode;
    	private String statut;
    	private String module;
    	private int ordre;
     
    	@Id
    	@Column (name="code_fonctionalite")
    	public String getCodeFonctionalite() {
    		return codeFonctionalite;
    	}
     
    	public void setCodeFonctionalite(String codeFonctionalite) {
    		this.codeFonctionalite = codeFonctionalite;
    	}
     
    	@Column (name="fonctionalite")
    	public String getFonctionalite() {
    		return fonctionalite;
    	}
     
     
    	public void setFonctionalite(String fonctionalite) {
    		this.fonctionalite = fonctionalite;
    	}
     
     
    	@Column (name="lien")
    	public String getLien() {
    		return lien;
    	}
     
     
    	public void setLien(String lien) {
    		this.lien = lien;
    	}
     
    	@Column (name="methode")
    	public String getMethode() {
    		return methode;
    	}
     
     
    	public void setMethode(String methode) {
    		this.methode = methode;
    	}
     
    	@Column (name="ordre")
    	public int getOrdre() {
    		return ordre;
    	}
     
     
    	public void setOrdre(int ordre) {
    		this.ordre = ordre;
    	}
     
     
    	@ManyToOne(fetch = FetchType.LAZY)
    	@JoinColumn (name="ref_parent")
    	public Fonctionnalite getParent() {
    		return parent;
    	}
     
    	public void setParent(Fonctionnalite parent) {
    		this.parent = parent;
    	}
     
    	@Column (name="statut")
    	public String getStatut() {
    		return statut;
    	}
     
    	public void setStatut(String statut) {
    		this.statut = statut;
    	}
     
    	@Column (name="module")
    	public String getModule() {
    		return module;
    	}
     
    	public void setModule(String module) {
    		this.module = module;
    	}
     
     
    }
    Profile
    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
    package winservices.mapping;
     
    import java.io.Serializable;
     
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table;
     
    import org.hibernate.annotations.Proxy;
     
    @Entity
    @Table(name="TBL_PROFILE")
    public class Profile implements Serializable{
     
    	private static final long serialVersionUID = 1L;
     
    	private String codeProfile;
    	private String profile;
     
    	@Id
    	@Column (name="code_profile")
    	public String getCodeProfile() {
    		return codeProfile;
    	}
    	public void setCodeProfile(String codeProfile) {
    		this.codeProfile = codeProfile;
    	}
     
    	@Column (name="profile")
    	public String getProfile() {
    		return profile;
    	}
    	public void setProfile(String profile) {
    		this.profile = profile;
    	}
    }
    ProfileFonctionnalte
    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
    package winservices.mapping;
     
    import java.io.Serializable;
     
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToMany;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
     
    import org.hibernate.annotations.Proxy;
     
     
    @Entity
    @Table(name="TBL_PROFILE_FONCTIONALITE")
    public class ProfileFonctionalite implements Serializable{
     
    	private static final long serialVersionUID = 1L;
     
    	private Long id;
    	private Profile profile;
    	private Fonctionnalite fonctionalite;
     
    	@Id
    	@Column (name="id")
    	public Long getId() {
    		return id;
    	}
    	public void setId(Long id) {
    		this.id = id;
    	}
     
     
    	@ManyToOne(fetch = FetchType.LAZY)
    	@JoinColumn (name="code_profile")
    	public Profile getProfile() {
    		return profile;
    	}
    	public void setProfile(Profile profile) {
    		this.profile = profile;
    	}
     
    	@ManyToOne(fetch = FetchType.LAZY)
    	@JoinColumn (name="code_fonctionalite")
    	public Fonctionnalite getFonctionalite() {
    		return fonctionalite;
    	}
    	public void setFonctionalite(Fonctionnalite fonctionalite) {
    		this.fonctionalite = fonctionalite;
    	}
     
     
    }
    Dans la classe DAO, je fais une requete qui retourne une liste d'objet ProfileFonctionnalite (chose faite) dont chaque objet ProfileFonctionnalite pointe sur une liste d'objet Fonctionnalite
    mais quand je debuggue je trouve les objets Foctionnalite ne sont pas renseignés.
    Est ce quelqu'un peut me donner un coup de main?

    La requete:
    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
    @SuppressWarnings("unchecked")
    	public List<ProfileFonctionalite> getListFonctionalitesParProfil( Profile profile)  throws Exception
    	 {
    		List <ProfileFonctionalite> listProfilesFonctionalites=null;
    		Session session = SessionFactoryUtil.getSessionFactory().openSession();
    	    try 
    	    {  
    	    	String queryString = "from ProfileFonctionalite pf where pf.profile= :profile order by pf.fonctionalite.ordre ";	    	
    	    	Query  query = session.createQuery(queryString);
    	    	query.setParameter("profile", profile);
    	    	listProfilesFonctionalites = query.list();
    	    }
    	    catch (Exception e)
    	    {
    	    	throw e;
    	    }
    	    return listProfilesFonctionalites;
    	}
    Merci d'avance

  2. #2
    Membre chevronné
    Homme Profil pro
    Inscrit en
    Octobre 2011
    Messages
    251
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2011
    Messages : 251
    Par défaut
    Tu as annoté tes deux objets propriete et fonctionalite en LAZY (chargement tardif), c'est pour cela que tes objets en sont pas initialisés.
    Si tu veux qu'ils soient chargés, soit tu passe les deux propriétés en EAGER, soit tu force leur chargement dans ta requête HQL.
    Cela devrait être un truc du genre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    String queryString = "from ProfileFonctionalite pf JOIN FETCH pf.profile JOIN FETCH pf.FONCTIONALITE where pf.profile= :profile order by pf.fonctionalite.ordre ";

  3. #3
    Membre confirmé
    Inscrit en
    Juillet 2007
    Messages
    64
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 64
    Par défaut
    Merci d'avoir répondu;
    Je ne suis pas au bureau, présentement mais je vous mettrai au courant de la suite.
    Encore merci

  4. #4
    Membre confirmé
    Inscrit en
    Juillet 2007
    Messages
    64
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 64
    Par défaut
    j'ai testé la requete que vous m'avez proposer, et c'est bien les objets fonctionnalités sont chargés aussi.

    Mais un autre soucis se pose:
    si vous regarder la classe Fonctionnalite, il y a un attribut parent qui est aussi de type Fonctionnalite.
    Le probleme maintenant est que les objet Fonctionnalite de ProfileFonctionnalite sont chargés mais l'obejt leurs attributs parent sont vide.
    Est ce qu'il ya une façon de modifier la requete pour que ça fonctionne.
    j'ai essayé ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    String queryString = "from ProfileFonctionalite pf JOIN FETCH pf.profile JOIN FETCH pf.fonctionalite JOIN FETCH pf.fonctionalite.parent where pf.profile= :profile order by pf.fonctionalite.ordre ";
    mais ça ne marche pas
    Encore merci,

  5. #5
    Membre confirmé
    Inscrit en
    Juillet 2007
    Messages
    64
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 64
    Par défaut
    merci bcp, ça marche tres bien avec la requete,

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

Discussions similaires

  1. Problème d'annotation hibernate
    Par yaya0057 dans le forum Hibernate
    Réponses: 2
    Dernier message: 03/03/2009, 10h03
  2. Réponses: 1
    Dernier message: 18/05/2006, 12h17
  3. Annotations Hibernates
    Par DanZzz dans le forum Hibernate
    Réponses: 1
    Dernier message: 12/05/2006, 09h05
  4. problème plugin Hibernate pour struts
    Par kaikai dans le forum Struts 1
    Réponses: 2
    Dernier message: 12/05/2006, 08h32
  5. [Hibernate] Problème avec Hibernate et Eclipse 3
    Par theseuby dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 30/03/2006, 21h31

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