-->
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.  [ 1 post ] 
Author Message
 Post subject: org.hibernate.exception.SQLGrammarException:
PostPosted: Mon Jul 22, 2013 11:01 am 
Newbie

Joined: Mon Jul 22, 2013 10:45 am
Posts: 1
salut tous le monde .
j'ai un probléme avec hibernate j'arrive pas à voir ou est la cause .

Code de l'erreur :

Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.exception.SQLGrammarException: could not execute query
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.loader.Loader.doList(Loader.java:2235)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
   at org.hibernate.loader.Loader.list(Loader.java:2124)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at dao.GenericDao.findAll(GenericDao.java:34)
   at teste1.hibernateteste.main(hibernateteste.java:18)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.users users0_' at line 1
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
   at com.mysql.jdbc.Util.getInstance(Util.java:386)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
   at org.hibernate.loader.Loader.doQuery(Loader.java:697)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
   at org.hibernate.loader.Loader.doList(Loader.java:2232)
   ... 9 more
Exception in thread "main" java.lang.NullPointerException
   at teste1.hibernateteste.main(hibernateteste.java:19)


Code de la classe de teste :

Code:
package teste1;


import java.util.ArrayList;
import java.util.List;

import model.*;
import dao.*;
public class hibernateteste {

   /**
    * @param args
    */
   public static void main(String[] args) {
    Users user = new  Users();
    List<Users> users = new ArrayList<Users>();
    GenericDao<Users> userDAO = new GenericDao<Users>("Users");
    users = userDAO.findAll();
    for(int i=0;i<users.size();i++)
    {
       System.out.println(users.get(i).getNom()+" "+ users.get(i).getPrenom());
    }
   }
 
}


Code de la classe Users :

Code:
package model;

// Generated 22 juil. 2013 14:18:18 by Hibernate Tools 3.4.0.CR1

import java.util.HashSet;
import java.util.Set;

/**
* Users generated by hbm2java
*/
public class Users implements java.io.Serializable {

   private Integer id;
   private Roles roles;
   private String nom;
   private String prenom;
   private String adresse;
   private String tel;
   private String email;
   private String password;
   private Set postulers = new HashSet(0);
   private Set cvs = new HashSet(0);
   private Set actualites = new HashSet(0);
   private Set offres = new HashSet(0);

   public Users() {
   }

   public Users(Roles roles, String nom, String prenom, String adresse,
         String tel, String email, String password) {
      this.roles = roles;
      this.nom = nom;
      this.prenom = prenom;
      this.adresse = adresse;
      this.tel = tel;
      this.email = email;
      this.password = password;
   }

   public Users(Roles roles, String nom, String prenom, String adresse,
         String tel, String email, String password, Set postulers, Set cvs,
         Set actualites, Set offres) {
      this.roles = roles;
      this.nom = nom;
      this.prenom = prenom;
      this.adresse = adresse;
      this.tel = tel;
      this.email = email;
      this.password = password;
      this.postulers = postulers;
      this.cvs = cvs;
      this.actualites = actualites;
      this.offres = offres;
   }

   public Integer getId() {
      return this.id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public Roles getRoles() {
      return this.roles;
   }

   public void setRoles(Roles roles) {
      this.roles = roles;
   }

   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 getTel() {
      return this.tel;
   }

   public void setTel(String tel) {
      this.tel = tel;
   }

   public String getEmail() {
      return this.email;
   }

   public void setEmail(String email) {
      this.email = email;
   }

   public String getPassword() {
      return this.password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   public Set getPostulers() {
      return this.postulers;
   }

   public void setPostulers(Set postulers) {
      this.postulers = postulers;
   }

   public Set getCvs() {
      return this.cvs;
   }

   public void setCvs(Set cvs) {
      this.cvs = cvs;
   }

   public Set getActualites() {
      return this.actualites;
   }

   public void setActualites(Set actualites) {
      this.actualites = actualites;
   }

   public Set getOffres() {
      return this.offres;
   }

   public void setOffres(Set offres) {
      this.offres = offres;
   }

}


Code GenricDao :

Code:
package dao;

import util.HibernateUtil;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
*
* @author uchiha itachi
*/
public class GenericDao<T> {
    Session session = null;
    String Table =null;
    public GenericDao(String table) {
        Table=table;
    }
    public void OpenSess()
    {
        session =  HibernateUtil.currentSession();
        session.beginTransaction().begin();
    }
    public void CloseSess()
    {
        session.beginTransaction().commit();
    }
    public List<T> findAll()
    {
        List<T> listeT = null;
        try
        {
            OpenSess();
            listeT=(List<T>)session.createQuery ("from "+Table).list();
            CloseSess();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return listeT;
    }
   
   /* public T findByID(String IDT,String coloneID)
    {
        List<T> listeT = null;
        try
        {
           OpenSess();           
           listeT= (List<T>)session.createQuery ("from "+Table+" as Alias where Alias."+coloneID+"='"+IDT+"'").list();
           CloseSess();
        }
        catch(Exception e)
        {e.printStackTrace();}
        return listeT.get(0);
    }*/
    public List<T> findByID(String IDT,String coloneID)
    {
        List<T> listeT = null;
        try
        {
           OpenSess();           
           listeT= (List<T>)session.createQuery ("from "+Table+" as Alias where Alias."+coloneID+"='"+IDT+"'").list();
           CloseSess();
        }
        catch(Exception e)
        {e.printStackTrace();}
        return listeT;
    }
    public void Save(T instance)
    {
       
        OpenSess();
        session.saveOrUpdate(instance);
        CloseSess();
    }
    public void Merge(T instance )
    {
       OpenSess();
        session.merge(instance);
        CloseSess();
    }
    public void Supprimer(T instance)
    {
        OpenSess();
        session.delete(instance);
        CloseSess();
    }
   
}


code de la classe hibenateutile :

Code:
package util;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

/**
* Hibernate Utility class with a convenient method to get Session Factory
* object.
*
* @author uchiha itachi
*/
public class HibernateUtil {

    private static final SessionFactory sessionFactory;
   
    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml)
            // config file.
            sessionFactory = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception.
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    public static final ThreadLocal session = new ThreadLocal();

    public static Session currentSession()
                   throws HibernateException {
      Session s = (Session) session.get();
      // Ouvre une nouvelle Session, si ce Thread n'en a aucune
      if (s == null) {
      s = sessionFactory.openSession();
      session.set(s);
      }
      return s;
      }
    public static SessionFactory getSessionFactory() {
       
       return sessionFactory;
    }
}


fichier hibernate config :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/bdcorporatesoftware</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.default_catalog">bdcorporatesoftware</property>
        <property name="hibernate.default_schema">bdcorporatesoftware</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
         <mapping resource="model/Offre.hbm.xml" />
        <mapping resource="model/Postuler.hbm.xml" />
        <mapping resource="model/Users.hbm.xml" />
        <mapping resource="model/Actualite.hbm.xml" />
        <mapping resource="model/Cv.hbm.xml" />
        <mapping resource="model/Roles.hbm.xml" />
    </session-factory>
</hibernate-configuration>

voila tius le code que j'ai generé avec hibernate reverse ingeneering et que j'ai tappé.
Merci pour votre aide !!!


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

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.