先整合了Spring和Hibernate编写了一个测试类Junit,但是不知道为什么测试类运行就出错,请大家帮我看看十分感谢困扰我好几天了。
错误信息如下:
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; 
nested exception is org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQLDialect;


Caused by: org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MySQLDialect;
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:104)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:65)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:460)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:155)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more
Application.xml如下:

解决方案 »

  1.   

    login.xml如下:
    loginTest如下:JAR包如下:
      

  2.   

    Application.xml没太发清楚我再重发次,大家一定要帮忙额,真头疼。<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="jdbcUrl">
    <value>jdbc:mysql://localhost:3306/bd_website?useUnicode=true&amp;characterEncoding=UTF-8
    </value>
    </property>
    <property name="user">
    <value>root</value>
    </property>
    <property name="password">
    <value>111</value>
    </property>
    </bean><bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
    <list>
    <value>cn/login/bean/Login.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.MySQLDialect;
    hibernate.hdm2ddl.auto=update;
    hibernate.show_sql=false;
       </value>
    </property>
    </bean>   <bean id="LoginDao" class="cn.login.daoimpl.LoginDaoImpl">
    <property name="sessionFactory">
    <ref local="sessionFactory" />
    </property>
       </bean></beans>
      

  3.   

    你先把你的图片传到csdn相册中,然后再引用。不然看不到图片别人没法帮你的。
      

  4.   

    org.hibernate.dialect.MySQLDialect;  这个方言找不到...你看看你的hibernate.jar对不对 有没有上面对应的那个类?<property name="dialect">org.hibernate.dialect.MySQLDialect</property>  
      

  5.   

    刚才传空间里了结果大家看不到重传下:login.xmljar:
    Test类:
      

  6.   

    没有装载连接数据的jar包吧! 把mysql连接架包加到工程里面 mysql-connector-java-3.1.13-bin.jar网上到处都是,注意版本就OK了。 其实提示信息已经很清晰了吧
      

  7.   

    mysql包我又导入了  还是那个错误没变额
      

  8.   

    mysql加上也不好用还是那个错误,大家给力呀
      

  9.   

    mysql方言没有找到,方言包没有导入
      

  10.   

    楼主看下你那hibernate-core.jar里有一个org.hibernate.dialect包
    在这个包里是否有MYSQLDialect.jar,正常的话应该是有的。
      

  11.   

    mysql驱动包   我导入了MYSQLDialect   在hibernate3.0jar包里为什么还出错呢
      

  12.   

    mysql那有方言包的...只导一个驱动就够了,其次楼主,你应该是检查下hibernate3.jar..有没有问题,跟着你试试<property name="dialect">org.hibernate.dialect.MySQLDialect</property>  
    对应这句话来,改改你的配置文件
      

  13.   

    MySQLDialect  这个类  我在TEST类里集成后导入  没有问题你们说会不会因为我Application.xml命名空间的问题?   这个我不知道怎么写
      

  14.   

    hibernate3中没有那个类吧。就是数据库方言mysql的那个类吧。
      

  15.   

                    hibernate.dialect=org.hibernate.dialect.MySQLDialect;
                    hibernate.hdm2ddl.auto=update;
                    hibernate.show_sql=false;这一段配置,把后面的;号去掉
      

  16.   

    看提示是方言包没有找到,你换个Hibernate包试试
      

  17.   

           <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect;
                    hibernate.hdm2ddl.auto=update;
                    hibernate.show_sql=false;
       </value>
    楼主,这个好像没有这样的写法吧,记得是<props>
    <prop name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></props>你试一下啊
      

  18.   

    jar包有冲突  你找找  应该是多了  
      

  19.   

     那个配置弄错了吧:
    <property name="name" type="java.lang.String">
    好像不是这样配置吧,那个type直接= string(小写的s) 就行了吧?
      

  20.   

    加JAR,方言包,单独的一个。
      

  21.   

            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect;
                    hibernate.hdm2ddl.auto=update;
                    hibernate.show_sql=false;
       </value>
            </property>
    能这么写么?setHibernateProperties(Properties prop)参数传错了吧?你可以先试试jdbc,测试一下你的dataSource是不是能连接成功。基本上方言上的问题都是没有获得连接引起的
      

  22.   

    申明类时找不到org.hibernate.dialect.MySQLDialect,你在IDE中 Ctrl+h 查询一下这个类,是多了还是一个也没有
      

  23.   

    谢谢大家的帮忙,错误找到了为了方便后来人,把错误公布下:错误1:
    正确:
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="show_sql">true</prop>
    我写成了:<prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>错误2,这个非常容易弄错:
    正确:
    <value>jdbc:mysql://localhost:3306/bd_website?useUnicode=true&amp;characterEncoding=UTF-8</value>我写成了:<value>jdbc:mysql://localhost:3306/bd_website?useUnicode=true&amp;characterEncoding=UTF-8
    </value>
      

  24.   

    Ssh2项目已经整合完毕,有需要的朋友可以点我的下载。