【问题标题】:What is the name dialect class for mysql 10.1.21-MariaDBmysql 10.1.21-MariaDB 的方言类名称是什么
【发布时间】:2018-07-05 17:25:01
【问题描述】:

在 hibernate.cfg.xml 中

我正在使用 MariaDBDialect 类

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Book</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"></property>
    <property name="hibernate.connection.pool_size">1</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MariaDBDialect</property>

    <mapping class="com.yazeed.brain.dto.User" />
</session-factory>

当我运行我的代码时,我在控制台中遇到了这个错误

Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.exception.SQLGrammarException: Error calling Driver#connect 
Caused by: java.sql.SQLSyntaxErrorException: Unknown database 'book'

【问题讨论】:

    标签: java hibernate maven


    【解决方案1】:

    您应该使用 org.hibernate.dialect.MySQLDialect,因为 MariaDB 与 mysql 100% 兼容。

    【讨论】:

    • 我在线程 "main" org.hibernate.MappingException 中遇到异常:未知实体:com.yazeed.brain.dto.Humans
    • 我在 com.yazeed.brain.dto 中有类 Humans,带有 @entity 注释 @Entity public class Humans { }
    • 你添加了@Table(name="humans") 并且检查了休眠配置应该使用AnnotationConfiguration而不是Configuration
    • 还要检查hibernate配置应该使用AnnotationConfiguration而不是Configuration
    • Configuration configuration = new Configuration().configure(); StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory factory = configuration.buildSessionFactory(builder.build()); Session session = factory.openSession(); session.beginTransaction(); session.save(user); session.getTransaction().commit();
    【解决方案2】:

    您也可以使用org.hibernate.dialect.MariaDB53Dialect 代替org.hibernate.dialect.MariaDBDialect

    【讨论】:

      猜你喜欢
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 2020-05-04
      • 2011-02-22
      相关资源
      最近更新 更多