These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [Debutant] Problème association
PostPosted: Thu Mar 09, 2006 1:50 pm 
Newbie

Joined: Thu Mar 09, 2006 1:39 pm
Posts: 2
Bonjour,

J'ai un problème, j'ai regardé la doc, et j'ai acheté le bouquin de M.Patricio, mais il y a un problème que je n'arrive pas a résoudre.

Tout d'abord pose mes fichiers mapping..ect..

Mapping Editeur
Code:
<hibernate-mapping>
  <class name="editeur.Editeur" table="EDITEUR">
    <id name="id" column="CODE_EDITEUR">
    <generator class="native"/>
    </id>
   <property name="nom" column="NOM"/>
    <property name="ville" column="VILLE" not-null="false"/>
  </class>
</hibernate-mapping>


Class Editeur
Code:
public class Editeur {
    private Long id;
    private String nom;
    private String ville;

    public Editeur() {}

    public Long getId() {
        return id;
    }

    private void setId(Long id) {
        this.id = id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getVille() {
        return ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }
}


Mapping Livre
Code:
<hibernate-mapping>
  <class name="livre.Livre" table="LIVRE">
    <id name="id" column="CODE_LIVRE">
    <generator class="native"/>
    </id>
    <many-to-one name="LEditeur" class="editeur.Editeur" column="CODE_EDITEUR"/>   
     
   <property name="titre" column="TITRE"/>
   <property name="AnneeParution" column="ANNEE_PARUTION" not-null="false"/>
   <property name="PrixAchat" column="PRIX_ACHAT" not-null="false"/>
   <property name="DateAchat" type="timestamp" column="DATE_ACHAT" not-null="false"/>
   <property name="ExclusDuPret" column="EXCLUS_DU_PRET" not-null="false"/>

  </class>
</hibernate-mapping>


Class Livre
Code:
public class Livre {
    private Long id;
    private Editeur lediteur;
    private Section lasection;
    private String titre;
    private Long anneeparution;
    private Long prixachat;
    private Date dateachat;
    private Long exclusdupret;

    public Livre() {}

    public Long getid() {
        return id;
    }

    private void setId(Long id) {
        this.id = id;
    }
   
    public Editeur getLEditeur() {
        return lediteur;
    }

    public void setLEditeur(Editeur lediteur) {
        this.lediteur = lediteur;
    }
   
    public String getTitre() {
        return titre;
    }

    public void setTitre(String titre) {
        this.titre = titre;
    }
   
    public Long getAnneeParution() {
        return anneeparution;
    }

    public void setAnneeParution(Long anneeparution) {
        this.anneeparution = anneeparution;
    }
   
    public Long getPrixAchat() {
        return prixachat;
    }

    public void setPrixAchat(Long prixachat) {
        this.prixachat = prixachat;
    }
   
    public Date getDateAchat() {
        return dateachat;
    }

    public void setDateAchat(Date dateachat) {
        this.dateachat = dateachat;
    }
   
    public Long getExclusDuPret() {
        return exclusdupret;
    }

    public void setExclusDuPret(Long exclusdupret) {
        this.exclusdupret = exclusdupret;
    }

}


Voici ma class de test

Code:
public class TestLivre
{
   public static void main(String args[])
    {
      TestLivre mgr = new TestLivre();
       
        List livres = mgr.listLivres();
       
        for (int i = 0; i < livres.size(); i++)
        {
            Livre LeLivre = (Livre)livres.get(i);
            Editeur Ed=LeLivre.getLEditeur();
         
           
            System.out.println("Titre: " + LeLivre.getTitre() + " | Editeur :" + Ed.getNom());
           
        }

        HibernateUtil.getSessionFactory().close();
    }

    private List listLivres() {

        Session session = HibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();

        List result = session.createQuery("from Livre").list();
       
        session.getTransaction().commit();

        return result;
    }
}


J'ai une table Livre remplie de Livre et une table editeur remplie d'editeur.
Tout les livres sont associé a un editeur.

Le problème est que j'arrive a recuperer l'ID de l'editeur, mais pas ses propriétées ( nom ou ville)..

J'ai essayer beaucoup de choses, je pense que le problème viens de la Query, j'ai essayé de la manipulé dans tous les sens, mais sans succès. Ce n'est peut etre pas ca..

Quelqu'un a une idée ? Merci d'avance pour votre aide.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 6:59 am 
Newbie

Joined: Thu Mar 09, 2006 1:39 pm
Posts: 2
J'ai résolu mon problème, c'etait la fin de semaine, un peu de fatigue et on fait n'importe quoi.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.