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

Hibernate Java Discussion :

Comment afficher une méthode Get appartenant à une classe via many-to-one ?


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de adil_vpb
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2006
    Messages
    326
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 326
    Par défaut Comment afficher une méthode Get appartenant à une classe via many-to-one ?
    bonjour,
    j'ai les classes suivantes :
    class AbstractTypeclient :
    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 abstract class AbstractTypeclient  implements java.io.Serializable {
     
     
        // Fields    
     
         private Integer idType;
         private String nameType;
     
     
        // Constructors
     
        /** default constructor */
        public AbstractTypeclient() {
        }
     
     
        /** full constructor */
        public AbstractTypeclient(String nameType) {
            this.nameType = nameType;
        }
     
     
        // Property accessors
     
        public Integer getIdType() {
            return this.idType;
        }
     
        public void setIdType(Integer idType) {
            this.idType = idType;
        }
     
        public String getNameType() {
            return this.nameType;
        }
     
        public void setNameType(String nameType) {
            this.nameType = nameType;
        }
     
     
     
     
     
     
     
     
     
    }
    et aussi classe AbstractClient :

    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
     
    public abstract class AbstractClient  implements java.io.Serializable {
     
     
        // Fields    
     
         private Integer idClt;
         private Integer typeClientIdType;
         private String rsClt;
         private String adressClt;
         private String telClt;
         private String gsmClt;
         private String faxClt;
         private String emailClt;
         private String villeClt;
     
     
        // Constructors
     
        /** default constructor */
        public AbstractClient() {
        }
     
    	/** minimal constructor */
        public AbstractClient(Integer typeClientIdType, String adressClt) {
            this.typeClientIdType = typeClientIdType;
            this.adressClt = adressClt;
        }
     
        /** full constructor */
        public AbstractClient(Integer typeClientIdType, String rsClt, String adressClt, String telClt, String gsmClt, String faxClt, String emailClt, String villeClt) {
            this.typeClientIdType = typeClientIdType;
            this.rsClt = rsClt;
            this.adressClt = adressClt;
            this.telClt = telClt;
            this.gsmClt = gsmClt;
            this.faxClt = faxClt;
            this.emailClt = emailClt;
            this.villeClt = villeClt;
        }
     
     
        // Property accessors
     
        public Integer getIdClt() {
            return this.idClt;
        }
     
        public void setIdClt(Integer idClt) {
            this.idClt = idClt;
        }
     
        public Integer getTypeClientIdType() {
            return this.typeClientIdType;
        }
     
        public void setTypeClientIdType(Integer typeClientIdType) {
            this.typeClientIdType = typeClientIdType;
        }
     
        public String getRsClt() {
            return this.rsClt;
        }
     
        public void setRsClt(String rsClt) {
            this.rsClt = rsClt;
        }
     
        public String getAdressClt() {
            return this.adressClt;
        }
     
        public void setAdressClt(String adressClt) {
            this.adressClt = adressClt;
        }
     
        public String getTelClt() {
            return this.telClt;
        }
     
        public void setTelClt(String telClt) {
            this.telClt = telClt;
        }
     
        public String getGsmClt() {
            return this.gsmClt;
        }
     
        public void setGsmClt(String gsmClt) {
            this.gsmClt = gsmClt;
        }
     
        public String getFaxClt() {
            return this.faxClt;
        }
     
        public void setFaxClt(String faxClt) {
            this.faxClt = faxClt;
        }
     
        public String getEmailClt() {
            return this.emailClt;
        }
     
        public void setEmailClt(String emailClt) {
            this.emailClt = emailClt;
        }
     
        public String getVilleClt() {
            return this.villeClt;
        }
     
        public void setVilleClt(String villeClt) {
            this.villeClt = villeClt;
        }
     
     
     
     
     
     
     
     
     
    }
    je voudrais mapper la relation :
    Un Typeclient a plusieurs Client, pour cela voici ce que j'ai utilisé dans les fichiers de map :
    Client.hbm.xml
    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
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="hibern.Client" table="client" catalog="belbouir">
            <id name="idClt" type="java.lang.Integer">
                <column name="id_CLT" />
                <generator class="increment" />
            </id>
             
            <many-to-one name="typeClientIdType" class="hibern.Typeclient" column="TypeClient_id_type"  not-null="true"/>
             
            
            <property name="rsClt" type="java.lang.String">
                <column name="rs_clt" length="100" />
            </property>
            <property name="adressClt" type="java.lang.String">
                <column name="adress_clt" not-null="true" />
            </property>
            <property name="telClt" type="java.lang.String">
                <column name="tel_clt" length="20" />
            </property>
            <property name="gsmClt" type="java.lang.String">
                <column name="gsm_clt" length="20" />
            </property>
            <property name="faxClt" type="java.lang.String">
                <column name="fax_clt" length="20" />
            </property>
            <property name="emailClt" type="java.lang.String">
                <column name="email_clt" length="45" />
            </property>
            <property name="villeClt" type="java.lang.String">
                <column name="ville_clt" length="20" />
            </property>
            
            
            
        </class>
    </hibernate-mapping>
    et le fichier Typeclient.hbm.xml:
    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
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="hibern.Typeclient" table="typeclient" catalog="belbouir">
            <id name="idType" type="java.lang.Integer">
                <column name="id_TYPE" />
                <generator class="increment" />
            </id>
            <property name="nameType" type="java.lang.String">
                <column name="name_type" length="20" />
            </property>
     
        </class>
    </hibernate-mapping>
    dans une classe java j'utilise :
    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
     
    package pack;
    public class Listing {
     
    	public List cltt;
     
    public List getCltt(){
     
    		ClientDAO dao = new ClientDAO();
    		List <Client> objet =  dao.findAll(Client.class);
     
    		cltt=objet;
    		return cltt;
     
    	}
    }
    Dans la page JSP, j'ai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    <jsp:directive.page import="java.util.* , pack.* "/>
    <html>
    <body>
    <jsp:useBean id="obj2" class="pack.Listing" scope="page" />
    <c:forEach var="client" items="${pageScope.obj2.cltt}" >
    ${client.idClt}  -> ${client.rsClt}     <br />
    </c:forEach>
    j'aimerai bine afficher au sein du foreach : -> et nameType c'est dans la classe AbstractTypeclient !

    est ce que c'est possible ?

    A savoir que à l'exécution de ma page JSP, j'ai les erreurs suivantes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    javax.servlet.ServletException: javax.servlet.jsp.el.ELException: An error occurred while getting property "cltt" from an instance of class pack.Listing
     
    org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of hibern.Client.setTypeClientIdType
    alors que dan HQL j'exécute la requête suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    select idClt,rsClt,typeClientIdType.nameType from Client
    , et elle me renvoie le résultat correct :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    23  Client1 Client Fidèle
    24  Client2 Client Fidèle
    25  Client4 Client Passager
    26  Client5 Client Passager

    Merci d'avance pour votre aide, car je suis vraiment bloqué dans cette phase

  2. #2
    Membre éclairé Avatar de adil_vpb
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Août 2006
    Messages
    326
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Août 2006
    Messages : 326
    Par défaut
    Bonjour,
    Est ce que ma question n'est pas trop clair ? si c'est le cas, je vous rappele que je souhaite seulement afficher une méthode Get ou un attribut d'une classe B qui est en relation avec la classe A via la balise <many-to-one>.

    Ex :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Classe A a un getNom();
    Classe B est en relation avec Classe A via <many-to-one ...>
     
    Est ce que c'est faisable lors de l'affichage des données, de faire un : 
     
    ClasseB objB=new ClasseB(.....); // Supposant que ce constructeur c'est session.load de Hibernate
    B.getNom(); // de la classe A
    Merci d'avance pour votre aide.

Discussions similaires

  1. Réponses: 1
    Dernier message: 06/12/2012, 09h46
  2. Réponses: 1
    Dernier message: 10/01/2009, 17h34
  3. Réponses: 2
    Dernier message: 05/01/2009, 12h45
  4. Réponses: 12
    Dernier message: 03/11/2005, 18h45
  5. copie d'une table Y d'une base A vers une table X d'une base
    Par moneyboss dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 30/08/2005, 21h24

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