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 :

[Hibernate] erreur database product name cannot be null


Sujet :

Hibernate Java

  1. #1
    Membre à l'essai
    Inscrit en
    Août 2005
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 31
    Points : 18
    Points
    18
    Par défaut [Hibernate] erreur database product name cannot be null
    salut tt le monde,
    je suis en train de faire du mapping avec une base de données en utilisant Hibernate. je l'ai configuré en programmation comme le suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     public  Configuration cfg = new Configuration();
    cfg.addClass(Client.class)
               .addClass(Card.class)
               .setProperty("connection.url",url)
               .setProperty("dialect",dialect)
               .setProperty("connection.username",username)
               .setProperty("connection.password",password)
               .setProperty("connection.driver_class",driver_class)
               .setProperty("myeclipse.connection.profile",profile);
    sessionFactory = cfg.buildSessionFactory();
    après l'exécution de mon TestHibernate, il m'affiche l'exception suivante, qui se déclenche à la ligne:
    sessionFactory = cfg.buildSessionFactory();

    org.hibernate.HibernateException: database product name cannot be null
    at org.hibernate.dialect.DialectFactory.determineDialect(
    DialectFactory.java:57)
    at org.hibernate.dialect.DialectFactory.buildDialect(
    DialectFactory.java:39)
    at org.hibernate.cfg.SettingsFactory.determineDialect(
    SettingsFactory.java:374)
    at org.hibernate.cfg.SettingsFactory.buildSettings(
    SettingsFactory.java:110)
    at org.hibernate.cfg.Configuration.buildSettings(
    Configuration.java:1463)
    at org.hibernate.cfg.Configuration.buildSessionFactory(
    Configuration.java:1004)
    at com.genuitec.hibernate.SessionManager.currentSession(
    SessionManager.java:69)
    at com.genuitec.hibernate.testHibernate.main(
    testHibernate.java:16)
    il y a qq qui a une idée. et merci beaucoup

  2. #2
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    essaie plutot hibernate.dialect et non dialect dans ton setProperty ... je t'invite a "copier" rigoureusement les indications du manuel HTML

    cf. ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Configuration cfg = new Configuration()
        .addClass(org.hibernate.auction.Item.class)
        .addClass(org.hibernate.auction.Bid.class)
        .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
        .setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test")
        .setProperty("hibernate.order_updates", "true");
    Bon courage !

  3. #3
    Membre à l'essai
    Inscrit en
    Août 2005
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 31
    Points : 18
    Points
    18
    Par défaut
    merci BizuR pr ta réponse. c'est résolu maintenant.
    moi j'ai copié auparavant les noms de mes propriétés à partir du fichier hibernate.cfg.xml que je n'utilise pas ici! c'est pr ça que j ne l'ai pas rendu compte!!
    Mais de quel manuel HTML que tu parles
    Merci

  4. #4
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Citation Envoyé par enimiste
    Mais de quel manuel HTML que tu parles
    Celui d'hibernate a cette adresse

  5. #5
    Futur Membre du Club
    Inscrit en
    Février 2007
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 18
    Points : 8
    Points
    8
    Par défaut connection a une base de donnée sql serveur 2000 avec hibernate
    salut tt le monde,

    je suis en train de faire une application web avec myeclipse4.1.1 et tomcat5.5.20 et JDK 1.5 et eclipse 3.1.2 et sql serveur 2000 pour creer ma base de données.

    je creer 4 tables ( clients,commandes, produits et detailcommandes ) avec des liens entre eux.

    mes classes ce sont:

    package com.jmd.library;

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

    public class Clients implements java.io.Serializable {


    // Fields

    private static final long serialVersionUID = 1L;
    private String cin;
    private String nom;
    private String prenom;
    private String adresse;
    private Set commandes = new HashSet(0);


    // Constructors

    /** default constructor
    * @param string3
    * @param string2
    * @param string */
    public Clients(String string, String string2, String string3) {
    }


    /** full constructor */
    public Clients(String nom, String prenom, String adresse, Set commandes) {
    this.nom = nom;
    this.prenom = prenom;
    this.adresse = adresse;
    this.commandes = commandes;
    }


    // Property accessors

    public Clients(String string, String string2, String string3, Date date) {
    }


    public String getCin() {
    return this.cin;
    }

    public void setCin(String cin) {
    this.cin = cin;
    }

    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 Set getCommandes() {
    return this.commandes;
    }

    public void setCommandes(Set commandes) {
    this.commandes = commandes;
    }


    public String getNomClients() {
    return null;
    }
    }

    et

    package com.jmd.library;

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

    public class Commandes implements java.io.Serializable {


    // Fields

    private static final long serialVersionUID = 1L;

    private Integer numcom;
    private Clients clients;
    private Date date;
    private Set detailcommandes = new HashSet(0);


    // Constructors

    /** default constructor */
    public Commandes() {
    }


    /** full constructor */
    public Commandes(Clients clients, Date date, Set detailcommandes) {
    this.clients = clients;
    this.date = date;
    this.detailcommandes = detailcommandes;
    }


    // Property accessors

    public Commandes(String string, Date date2) {
    }


    public Integer getNumcom() {
    return this.numcom;
    }

    public void setNumcom(Integer numcom) {
    this.numcom = numcom;
    }

    public Clients getClients() {
    return this.clients;
    }

    public void setClients(Clients clients) {
    this.clients = clients;
    }

    public Date getDate() {
    return this.date;
    }

    public void setDate(Date date) {
    this.date = date;
    }

    public Set getDetailcommandes() {
    return this.detailcommandes;
    }

    public void setDetailcommandes(Set detailcommandes) {
    this.detailcommandes = detailcommandes;
    }
    }

    et

    package com.jmd.library;

    public class DetailCommandes implements java.io.Serializable {


    // Fields

    private static final long serialVersionUID = 1L;

    private String id;
    private Produits produits;
    private Commandes commandes;
    private Integer qte;


    // Constructors

    /** default constructor */
    public DetailCommandes() {
    }

    /** minimal constructor */
    public DetailCommandes(Produits produits, Commandes commandes) {
    this.produits = produits;
    this.commandes = commandes;
    }

    /** full constructor */
    public DetailCommandes(Produits produits, Commandes commandes, Integer qte) {
    this.produits = produits;
    this.commandes = commandes;
    this.qte = qte;
    }


    // Property accessors

    public DetailCommandes(String string, String string2, String string3) {
    }

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

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

    public Produits getProduits() {
    return this.produits;
    }

    public void setProduits(Produits produits) {
    this.produits = produits;
    }

    public Commandes getCommandes() {
    return this.commandes;
    }

    public void setCommandes(Commandes commandes) {
    this.commandes = commandes;
    }

    public Integer getQte() {
    return this.qte;
    }

    public void setQte(Integer qte) {
    this.qte = qte;
    }
    }

    et

    package com.jmd.library;

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

    public class Produits implements java.io.Serializable {


    // Fields

    private static final long serialVersionUID = 1L;
    private Integer reference;
    private String libelle;
    private Long prix;
    private Set detailcommandes = new HashSet(0);


    // Constructors

    /** default constructor */
    public Produits() {
    }


    /** full constructor */
    public Produits(String libelle, Long prix, Set detailcommandes) {
    this.libelle = libelle;
    this.prix = prix;
    this.detailcommandes = detailcommandes;
    }


    // Property accessors

    public Produits(String string, String string2) {
    }


    public Integer getReference() {
    return this.reference;
    }

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

    public String getLibelle() {
    return this.libelle;
    }

    public void setLibelle(String libelle) {
    this.libelle = libelle;
    }

    public Long getPrix() {
    return this.prix;
    }

    public void setPrix(Long prix) {
    this.prix = prix;
    }

    public Set getDetailcommandes() {
    return this.detailcommandes;
    }

    public void setDetailcommandes(Set detailcommandes) {
    this.detailcommandes = detailcommandes;
    }
    }

    et le test de hibernate:

    package com.jmd.library;

    import java.util.Date;

    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.classic.Session;


    public class TestHibernate1 {

    public static void main(String args[])

    throws Exception {

    Configuration config = new Configuration();

    config.addClass(Clients.class);
    config.addClass(Commandes.class);
    config.addClass(Produits.class);
    config.addClass(DetailCommandes.class);

    SessionFactory sessionFactory = config.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction tx = null;

    try {
    tx = session.beginTransaction();
    Clients clients = new Clients("nom", "prenom", "adresse");
    session.save(clients);
    session.flush() ;
    tx.commit();
    //session.connection();

    tx = session.beginTransaction();
    Produits produits = new Produits("prix" , "libelle");
    session.save(produits);
    session.flush();
    tx.commit();
    //session.connection();

    tx = session.beginTransaction();
    Commandes commandes = new Commandes("cin", new Date());
    session.save(commandes);
    session.flush();
    tx.commit();
    //session.connection();

    tx = session.beginTransaction();
    DetailCommandes detailcommandes = new DetailCommandes("numcom", "reference", "qte");
    session.save(detailcommandes);
    session.flush();
    tx.commit();
    //session.connection();
    }

    catch (Exception e) {
    if (tx != null) {
    tx.rollback();
    }

    throw e;
    }
    finally {
    session.close();
    }
    sessionFactory.close();
    }
    }

    et les fichiers de mapping est:


    <?xml version="1.0"?>
    <!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="Clients" table="clients" schema="dbo" catalog="DBbase1">
    <id name="cin" type="java.lang.String">
    <column name="cin" length="10" />
    <generator class="sequence"></generator>
    </id>
    <property name="nom" type="java.lang.String">
    <column name="nom" />
    </property>
    <property name="prenom" type="java.lang.String">
    <column name="prenom" />
    </property>
    <property name="adresse" type="java.lang.String">
    <column name="adresse" />
    </property>
    <set name="commandes" inverse="true">
    <key>
    <column name="cin" length="10" />
    </key>
    <one-to-many class="Commandes" />
    </set>
    </class>
    </hibernate-mapping>

    et

    <?xml version="1.0"?>
    <!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="Commandes" table="commandes" schema="dbo" catalog="DBbase1">
    <id name="numcom" type="java.lang.Integer">
    <column name="numcom" />
    <generator class="sequence"></generator>
    </id>
    <many-to-one name="clients" class="Clients" fetch="select">
    <column name="cin" length="10" />
    </many-to-one>
    <property name="date" type="java.util.Date">
    <column name="date" length="23" />
    </property>
    <set name="detailcommandes" inverse="true">
    <key>
    <column name="numcom" not-null="true"/>
    </key>
    <one-to-many class="DetailCommandes" />
    </set>
    </class>
    </hibernate-mapping>

    et

    <?xml version="1.0"?>
    <!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="DetailCommandes" table="detailcommandes" schema="dbo" catalog="DBbase1">
    <id name="id" type="java.lang.String">
    <column name="id" length="10" />
    <generator class="sequence"></generator>
    </id>
    <many-to-one name="produits" class="Produits" fetch="select">
    <column name="reference" not-null="true"/>
    </many-to-one>
    <many-to-one name="commandes" class="Commandes" fetch="select">
    <column name="numcom" not-null="true"/>
    </many-to-one>
    <property name="qte" type="java.lang.Integer">
    <column name="qte" />
    </property>
    </class>
    </hibernate-mapping>

    et

    <?xml version="1.0"?>
    <!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="Produits" table="produits" schema="dbo" catalog="DBbase1">
    <id name="reference" type="java.lang.Integer">
    <column name="reference" />
    <generator class="sequence"></generator>
    </id>
    <property name="libelle" type="java.lang.String">
    <column name="libelle" />
    </property>
    <property name="prix" type="java.lang.Long">
    <column name="prix" precision="18" scale="0" />
    </property>
    <set name="detailcommandes" inverse="true">
    <key>
    <column name="reference" not-null="true"/>
    </key>
    <one-to-many class="DetailCommandes" />
    </set>
    </class>
    </hibernate-mapping>

    et le fichier de hibernatesessionfactory:

    package com.jmd.teste;

    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;

    public class HibernateSessionFactory {


    private static final SessionFactory sessionFactory;

    static {
    try {
    // Crée la SessionFactory
    sessionFactory = new Configuration().configure().buildSessionFactory();
    }
    catch (HibernateException ex) {
    throw new RuntimeException("Problème de configuration : "
    + ex.getMessage(), ex);
    }
    }

    public static final ThreadLocal session = new ThreadLocal();

    @SuppressWarnings("unchecked")
    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;
    }

    @SuppressWarnings("unchecked")
    public static void closeSession()
    throws HibernateException {
    Session s = (Session) session.get();
    session.set(null);
    if (s != null)
    s.close();
    }
    }

    et le fichier hibernate.cfg.xml:

    <?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">

    <!-- Generated by MyEclipse Hibernate Tools.-->
    <hibernate-configuration>

    <session-factory>
    <property name="hibernate.connection.username">khalil</property>
    <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433/DBbase1</property>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="myeclipse.connection.profile">BaseCommandes</property>
    <property name="hibernate.connection.password">password</property>
    <property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
    <property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory></property>
    <mapping resource="Produits.hbm.xml" />
    <mapping resource="Commandes.hbm.xml" />
    <mapping resource="DetailCommandes.hbm.xml" />
    <mapping resource="Clients.hbm.xml" />

    </session-factory>

    </hibernate-configuration>


    et pour tous ca, après l'exécution de mon TestHibernate, il m'affiche l'exception suivante:

    0 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.0.5
    15 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    15 [main] INFO org.hibernate.cfg.Environment - using CGLIB reflection optimizer
    15 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
    Exception in thread "main" 78 [main] INFO org.hibernate.cfg.Configuration - Mapping resource: com/jmd/library/Clients.hbm.xml
    468 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Clients -> clients
    484 [main] INFO org.hibernate.cfg.Configuration - Mapping resource: com/jmd/library/Commandes.hbm.xml
    531 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Commandes -> commandes
    593 [main] INFO org.hibernate.cfg.Configuration - Mapping resource: com/jmd/library/Produits.hbm.xml
    625 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: Produits -> produits
    625 [main] INFO org.hibernate.cfg.Configuration - Mapping resource: com/jmd/library/DetailCommandes.hbm.xml
    656 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: DetailCommandes -> detailcommandes
    656 [main] INFO org.hibernate.cfg.Configuration - processing extends queue
    656 [main] INFO org.hibernate.cfg.Configuration - processing collection mappings
    656 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: Clients.commandes -> commandes
    656 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: Commandes.detailcommandes -> detailcommandes
    656 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: Produits.detailcommandes -> detailcommandes
    656 [main] INFO org.hibernate.cfg.Configuration - processing association property references
    656 [main] INFO org.hibernate.cfg.Configuration - processing foreign key constraints
    672 [main] WARN org.hibernate.connection.UserSuppliedConnectionProvider - No connection properties specified - the user must supply JDBC connections
    org.hibernate.HibernateException: database product name cannot be null
    at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
    at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:374)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
    at com.jmd.library.TestHibernate1.main(TestHibernate1.java:24)


    j ai le même erreur

    et merci d'avance.

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

Discussions similaires

  1. Erreur "entity for parameter binding cannot be null"
    Par angel.success dans le forum Java EE
    Réponses: 22
    Dernier message: 25/05/2012, 19h33
  2. Réponses: 2
    Dernier message: 17/02/2012, 14h11
  3. Réponses: 0
    Dernier message: 25/08/2009, 16h59
  4. [Hibernate] : Erreur Could not find datasource
    Par tipaquo dans le forum Hibernate
    Réponses: 2
    Dernier message: 12/10/2005, 10h43
  5. [EJB][JBOSS] ejb column cannot be null
    Par alfredeu dans le forum Wildfly/JBoss
    Réponses: 2
    Dernier message: 14/04/2005, 09h40

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