java hibernate 4 org.hibernate.HibernateException:找不到方言类:org.hibernate.dialect.MYSQLDialect [英] java hibernate 4 org.hibernate.HibernateException: Dialect class not found: org.hibernate.dialect.MYSQLDialect

查看:434
本文介绍了java hibernate 4 org.hibernate.HibernateException:找不到方言类:org.hibernate.dialect.MYSQLDialect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Eclipse中创建了一个动态Web项目,我'已经将它转换成MAVEN项目,将mysql-connector-java和hibernate-core依赖项添加到pom.xml中。
我已经添加了一个servlet,并且在doGet方法中,我尝试初始化sessionfactory来创建表。我正在使用tomcat。

在向servlet发出请求时,我收到以下异常:

  org.hibernate.HibernateException:找不到方言类:org.hibernate.dialect.MYSQLDialect 
org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect (DialectFactoryImpl.java:77)
org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:65)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure (JdbcServicesImpl.java:146)
org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160 )
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132)
org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1818)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1776)
hu.adamsan.testhibernate.TestHibernate.doGet(TestHibernate.java:74)

pom.xml:

 依赖项> 
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< version> 5.1.26< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 4.2.6.Final< / version>
< /依赖关系>
< /依赖关系>

我试着去研究Maven Dependencies,org.hibernate.dialect.MySQLDialect.class是在那里,位置:getServletContext()。getRealPath(。) - > E:\eclips_jee\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ TestHibernateWeb\\
,在WEB-INF\lib目录中有hibernate-core-4.2.6.Final.jar,当我用7zip打开它时,可以在org / hibernate / dialect / MySQL5Dialect.class。



我错过了什么?我真的不知道。



doGet方法:

  PrintWriter w = response.getWriter(); 
w.println(测试休眠< br />);
w.println(getServletContext()。getRealPath(。)+< br />);

配置配置;
ServiceRegistry注册表;
SessionFactory工厂;
config = new Configuration()。addAnnotatedClass(Modell.class);
属性props = getProperties();
props.setProperty(Environment.HBM2DDL_AUTO,create);
config.setProperties(道具);
registry = new ServiceRegistryBuilder()。applySettings(props).buildServiceRegistry();
factory = config.buildSessionFactory(registry);
factory.close();


解决方案

答案在问题中。您在jar文件中发现了 MySQLDialect MySQL5Dialect ,但是您的配置文件尝试使用 MYSQLDialect 。 Java是区分大小写的。


I'm learning Java EE and Hibernate, and I've run into the following problem:

I've created a Dynamic Web Project in Eclipse, I've converted it into a MAVEN project, added the mysql-connector-java and the hibernate-core dependencies to the pom.xml. I've added a servlet, and in the doGet method, I've tried to initialize the sessionfactory to create the tables. I'm using tomcat.

When I'm making a request to the servlet I'm getting the following exception:

org.hibernate.HibernateException: Dialect class not found:   org.hibernate.dialect.MYSQLDialect
 org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:77)
org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:65)
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:146)
org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132)
org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1818)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1776)
hu.adamsan.testhibernate.TestHibernate.doGet(TestHibernate.java:74)

pom.xml:

dependencies>
    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.26</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.6.Final</version>
        </dependency>
</dependencies>

I've tried to look into the Maven Dependencies, org.hibernate.dialect.MySQLDialect.class is in there, in the location: getServletContext().getRealPath(".") ->E:\eclips_jee\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestHibernateWeb\ , in the WEB-INF\lib directory, there is hibernate-core-4.2.6.Final.jar, when I opened it with 7zip, I could find inside the org/hibernate/dialect/MySQL5Dialect.class.

What am I missing? I really have no idea.

doGet method:

    PrintWriter w = response.getWriter();
    w.println("Testing hibernate<br/>");
    w.println(getServletContext().getRealPath(".")+"<br/>");

    Configuration config;
    ServiceRegistry registry;
    SessionFactory factory;     
    config = new Configuration().addAnnotatedClass(Modell.class);       
    Properties props = getProperties();     
    props.setProperty(Environment.HBM2DDL_AUTO, "create");      
    config.setProperties(props);        
    registry = new ServiceRegistryBuilder().applySettings(props).buildServiceRegistry();        
    factory = config.buildSessionFactory(registry);     
    factory.close();

解决方案

The answer is in the question. You've found MySQLDialect and MySQL5Dialect in your jar files, but your configuration file tries to use MYSQLDialect. Java is case-sensitive.

这篇关于java hibernate 4 org.hibernate.HibernateException:找不到方言类:org.hibernate.dialect.MYSQLDialect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆