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 :

probleme avec la methode load


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de thaundeadboss
    Homme Profil pro
    Développeur COBOL & JAVA
    Inscrit en
    Février 2007
    Messages
    211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur COBOL & JAVA
    Secteur : Finance

    Informations forums :
    Inscription : Février 2007
    Messages : 211
    Par défaut probleme avec la methode load
    j'ai une fonction qui doit recuperer un enregistrement d'une base de données .
    je travaille avec hibernate 3 du coup je trouve plus la methode find(String arg0) j'ai essayé alors la methode load mais celle ci me retourne NullPointerException

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Il faut croire qu'à l'identifiant que tu utilises avec ta méthode load ne correspond aucun objet en base.
    Montre nous ton code.

  3. #3
    Membre éclairé Avatar de thaundeadboss
    Homme Profil pro
    Développeur COBOL & JAVA
    Inscrit en
    Février 2007
    Messages
    211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur COBOL & JAVA
    Secteur : Finance

    Informations forums :
    Inscription : Février 2007
    Messages : 211
    Par défaut
    desole je vien de revoir ma classe en effet dans la base le client à un id composé d'un radical et d'un num d'itentite alors hibernate à mapper la classe physiqueId dont les champs sont les deux identifiant .
    j'aimerais savoir comment faire une selection à la base d'un seul identifiant soit le radical ou le num d'itentite

    code de la classe client Physique
    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
     
    package cls;
    // Generated 8 juil. 2009 10:49:24 by Hibernate Tools 3.2.4.GA
     
    /**
     * Physique generated by hbm2java
     */
    public class Physique implements java.io.Serializable {
     
    	private PhysiqueId id;
    	private Client client;
    	private String nom;
    	private String prenom;
    	private String adresse;
    	private String ville;
    	private String codepostal;
    	private String tel;
     
    	public Physique() {
    	}
     
    	public Physique(PhysiqueId id, Client client, String nom, String prenom,
    			String adresse, String ville, String codepostal, String tel) {
    		this.id = id;
    		this.client = client;
    		this.nom = nom;
    		this.prenom = prenom;
    		this.adresse = adresse;
    		this.ville = ville;
    		this.codepostal = codepostal;
    		this.tel = tel;
    	}
     
    	public PhysiqueId getId() {
    		return this.id;
    	}
     
    	public void setId(PhysiqueId id) {
    		this.id = id;
    	}
     
    	public Client getClient() {
    		return this.client;
    	}
     
    	public void setClient(Client client) {
    		this.client = client;
    	}
     
    	public String getNom() {
    		return this.nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getPrenom() {
    		return this.prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	public String getAdresse() {
    		return this.adresse;
    	}
     
    	public void setAdresse(String adresse) {
    		this.adresse = adresse;
    	}
     
    	public String getVille() {
    		return this.ville;
    	}
     
    	public void setVille(String ville) {
    		this.ville = ville;
    	}
     
    	public String getCodepostal() {
    		return this.codepostal;
    	}
     
    	public void setCodepostal(String codepostal) {
    		this.codepostal = codepostal;
    	}
     
    	public String getTel() {
    		return this.tel;
    	}
     
    	public void setTel(String tel) {
    		this.tel = tel;
    	}
     
    }
    code de la classe de la cle composite
    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
     
    package cls;
    // Generated 8 juil. 2009 10:49:24 by Hibernate Tools 3.2.4.GA
     
    /**
     * PhysiqueId generated by hbm2java
     */
    public class PhysiqueId implements java.io.Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 986132205814515151L;
    	private int radical;
    	private String cin;
     
    	public PhysiqueId() {
    	}
     
    	public PhysiqueId(int radical, String cin) {
    		this.radical = radical;
    		this.cin = cin;
    	}
     
    	public int getRadical() {
    		return this.radical;
    	}
     
    	public void setRadical(int radical) {
    		this.radical = radical;
    	}
     
    	public String getCin() {
    		return this.cin;
    	}
     
    	public void setCin(String cin) {
    		this.cin = cin;
    	}
     
    	public boolean equals(Object other) {
    		if ((this == other))
    			return true;
    		if ((other == null))
    			return false;
    		if (!(other instanceof PhysiqueId))
    			return false;
    		PhysiqueId castOther = (PhysiqueId) other;
     
    		return (this.getRadical() == castOther.getRadical())
    				&& ((this.getCin() == castOther.getCin()) || (this.getCin() != null
    						&& castOther.getCin() != null && this.getCin().equals(
    						castOther.getCin())));
    	}
     
    	public int hashCode() {
    		int result = 17;
     
    		result = 37 * result + this.getRadical();
    		result = 37 * result
    				+ (getCin() == null ? 0 : this.getCin().hashCode());
    		return result;
    	}
     
    }
    voila le fichier de mapping de la classe physique
    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
     
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 8 juil. 2009 10:49:25 by Hibernate Tools 3.2.4.GA -->
    <hibernate-mapping>
        <class name="cls.Physique" table="physique" catalog="instruction_credits">
            <composite-id name="id" class="cls.PhysiqueId">
                <key-property name="radical" type="int">
                    <column name="radical" />
                </key-property>
                <key-property name="cin" type="string">
                    <column name="cin" length="20" />
                </key-property>
            </composite-id>
            <many-to-one name="client" class="cls.Client" update="false" insert="false" fetch="select">
                <column name="radical" not-null="true" />
            </many-to-one>
            <property name="nom" type="string">
                <column name="nom" length="45" not-null="true" />
            </property>
            <property name="prenom" type="string">
                <column name="prenom" length="45" not-null="true" />
            </property>
            <property name="adresse" type="string">
                <column name="adresse" length="45" not-null="true" />
            </property>
            <property name="ville" type="string">
                <column name="ville" length="45" not-null="true" />
            </property>
            <property name="codepostal" type="string">
                <column name="codepostal" length="45" not-null="true" />
            </property>
            <property name="tel" type="string">
                <column name="tel" length="45" not-null="true" />
            </property>
        </class>
    </hibernate-mapping>
    et merci pour ta precieuse coopération.

  4. #4
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Et en passant à load un PhysiqueId initialisé avec les bonnes valeurs ?

  5. #5
    Membre éclairé Avatar de thaundeadboss
    Homme Profil pro
    Développeur COBOL & JAVA
    Inscrit en
    Février 2007
    Messages
    211
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur COBOL & JAVA
    Secteur : Finance

    Informations forums :
    Inscription : Février 2007
    Messages : 211
    Par défaut
    s'il vous plait je ne saurais le faire je ne suisque debutant dans hibernate si vous pouvez me donne un indice .

  6. #6
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    //mettre les bonnes valeurs de ton id
    PhysiqueId id = new PhysiqueId(2, "aaa");
     
    Physique tonObjet = taSession.load(Physique.class, id);

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

Discussions similaires

  1. probleme avec une methode static dans le body d'une jsp
    Par amadou.deme dans le forum Servlets/JSP
    Réponses: 10
    Dernier message: 19/02/2007, 08h47
  2. Probleme avec la methode readLine()!
    Par thenightmare1985 dans le forum Entrée/Sortie
    Réponses: 4
    Dernier message: 26/10/2006, 20h00
  3. [JTextArea]Probleme avec la methode select
    Par caneman dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 30/07/2006, 14h50
  4. [VB.NET] Probleme avec la methode ReadToEnd
    Par Aspic dans le forum VB.NET
    Réponses: 2
    Dernier message: 02/12/2005, 21h10
  5. [Struts] Problème avec la méthode validate
    Par clement42 dans le forum Struts 1
    Réponses: 2
    Dernier message: 09/06/2005, 10h52

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