第一个Hibernate测试给出错误[EDITED]

时间:2015-10-02 20:58:33

标签: java android spring hibernate

我是一名Hibernate初学者用户,我创建了一个非常简单的应用程序来测试它! 但是我在控制台中收到了这个错误:

    Initial SessionFactory creation failed.org.hibernate.HibernateException: Dialect class not found: org.openmeetings.app.hibernate.utils.MySQL5MyISAMDialect
Exception in thread "main" java.lang.ExceptionInInitializerError
   at util.HibernateUtil.buildSessionFactory(HibernateUtil.java:20)
   at util.HibernateUtil.<clinit>(HibernateUtil.java:10)
   at DAO.services.addProduit(services.java:9)
   at test.main(test.java:11)
Caused by: org.hibernate.HibernateException: Dialect class not found: org.openmeetings.app.hibernate.utils.MySQL5MyISAMDialect
   at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:81)
   at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:42)
   at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:422)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
   at util.HibernateUtil.buildSessionFactory(HibernateUtil.java:15)
   ... 3 more

我的测试课程:

import DAO.services;
import DAO.Produit;

public class test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        services s = new services();
        Produit p = new Produit("PC","Sony Vaio",(double )7500);
        s.addProduit(p);

    }

}

Hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<!-- Generated file - Do not edit! -->

<hibernate-configuration>

        <!-- a SessionFactory instance listed as /jndi/name -->
        <session-factory>

                <!-- User  / Password -->
                <property name="connection.username">root</property>
                <property name="connection.password"></property>

                <!-- Database Settings -->
                <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
                <!--  for performance reasons changed to MyISAM from org.hibernate.dialect.MySQLInnoDBDialect -->
                <property name="dialect">org.openmeetings.app.hibernate.utils.MySQL5MyISAMDialect</property>
                <property name="connection.url">jdbc:mysql://localhost:3306/gestProd</property>     

                <property name="hibernate.connection.CharSet">utf8</property>
                <property name="hibernate.connection.characterEncoding">utf8</property>
                <property name="hibernate.connection.useUnicode">true</property>


                <!-- Database Scheme Auto Update -->
                <property name="hbm2ddl.auto">update</property>                 

                <!-- properties -->

                <property name="show_sql">true</property>
                <property name="use_outer_join">false</property>
                <property name="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</property>
        <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
        <!--
        <property name="connection.provider_class ">org.hibernate.connection.C3P0ConnectionProvider</property>
         -->
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.cache.use_query_cache">false</property>
        <property name="hibernate.cache.use_second_level_cache">false</property>
        <property name="hibernate.generate_statistics">false</property>
        <property name="hibernate.cache.use_structured_entries">false</property>


        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.min_size">2</property>
        <property name="hibernate.c3p0.idle_test_period">100</property>
        <property name="hibernate.c3p0.max_statements">100</property>
        <property name="hibernate.c3p0.timeout">100</property>

                <!-- mapping files -->
        <mapping resource="DAO/Categorie.hbm.xml"/>
        <mapping resource="DAO/Produit.hbm.xml"/>        


        </session-factory>

</hibernate-configuration>

service.java:

package DAO;

import org.hibernate.Session;
import util.HibernateUtil;
public class services {

    public void addProduit(Produit p){

        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.save(p);
        session.getTransaction().commit();

    }

}

最后我的对象(Produit和Categorie)及其配置文件的两个类!

您认为这个错误的根源是什么?

谢谢:)

1 个答案:

答案 0 :(得分:0)

MySql与MyISAM的方言(如果你有的话)应该是:

  

org.hibernate.dialect.MySQLMyISAMDialect