-->
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.  [ 4 posts ] 
Author Message
 Post subject: Commande is not mapped [from Commande]
PostPosted: Wed Oct 08, 2008 8:10 am 
Newbie

Joined: Tue Oct 07, 2008 3:55 pm
Posts: 4
Bonjour , débutant en hibernate , j'ai du mal à débugguer un problème.

Voici la classe test qui génére l'erreur (qui est d'ailleurs présente dès que je touche à la table ou l'objet Commande).

Code:
public class TestCommandeLister {
 
  public static void main(String args[]) throws Exception {
    Configuration config = new Configuration();
    config.addClass(Article.class);
    SessionFactory sessionFactory = config.buildSessionFactory();
    Session session = sessionFactory.openSession();

    try {
      Query query = session.createQuery("from Commande");
      List commandes = query.list();
      for (int i = 0; i < commandes.size(); i++) {
         Commande commande = (Commande) commandes.get(i);
        System.out.println("nom = " + commande.getReference());
      }
    } finally {
      session.close();
    }
    sessionFactory.close();
  }


L'erreur générée
Code:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Commande is not mapped [from Commande]
   at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
   at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
   at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
   at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
   at test.TestCommandeLister.main(TestCommandeLister.java:22)


Mon fichier Mapping
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="mywebapp.persistance.data.Commande" table="commande">
      <id name="reference" type="string"><generator class="assigned" /></id>
         <property name="quantite" type="int" not-null="true" />
   </class>
</hibernate-mapping>


Mon fichier de configuration hibernate contient
Code:
   <mapping resource="mywebapp/persistance/data/Commande.hbm.xml" />


Ma classe Commande :
Code:
package mywebapp.persistance.data;

public class Commande {
   
   private Integer quantite;
   private String reference;
   
   public Commande(){}
   
   public Commande(String r, Integer i) {
      this.reference = r;
      this.quantite = i;
   }


   public Integer getQuantite() {
      return quantite;
   }

   public void setQuantite(Integer quantite) {
      this.quantite = quantite;
   }

   public String getReference() {
      return reference;
   }

   public void setReference(String reference) {
      this.reference = reference;
   };
   
}


Et le schéma de ma base
Code:

CREATE TABLE `commande` (
  `quantite` int(3) default NULL,
  `reference` varchar(15) NOT NULL default '',
  PRIMARY KEY  (`reference`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


Voilà si vous avez des idées pour débugguer , ça serait sympa.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2008 8:55 am 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
En hql, il faut mettre le nom de la classe pas de la table, essai:

Code:
from mywebapp.persistance.data.Commande


Christophe


Top
 Profile  
 
 Post subject: Re: Commande is not mapped [from Commande]
PostPosted: Wed Oct 08, 2008 9:13 am 
Newbie

Joined: Tue Oct 07, 2008 3:55 pm
Posts: 4
cotede4 wrote:
Bonjour , débutant en hibernate , j'ai du mal à débugguer un problème.

Voici la classe test qui génére l'erreur (qui est d'ailleurs présente dès que je touche à la table ou l'objet Commande).

[code]
public class TestCommandeLister {

public static void main(String args[]) throws Exception {
Configuration config = new Configuration();
config.addClass(Article.class);
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();


Commande.class


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 9:07 am 
Newbie

Joined: Mon Jun 16, 2008 8:53 am
Posts: 6
Il faut que ta classe etende HistorizedObject et implémente Serializable.

Rajoute ça aussi;
puublic class Commande extends HistorizedObject implements java.io.Serializable {

...
}

_________________
Solidaire dans la Galère... (à mediter)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.