在何处放置hibernate.dialect.storage\u engine属性

jjhzyzn0  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(298)

我用 MySQL5Dialect 替换 MySQL5InnoDBDialect 因为旧的已经过时了。

package org.hibernate.dialect;

/**A Dialect for MySQL 5 using InnoDB engine
 *
 * @author Gavin King,
 * @author Scott Marlow
 * @deprecated Use "hibernate.dialect.storage_engine=innodb" 
environment variable or JVM system property instead.
 */
@Deprecated
public class MySQL5InnoDBDialect extends MySQL5Dialect {

@Override
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
    return InnoDBStorageEngine.INSTANCE;
    }
}

我的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">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.id.new_generator_mappings">false</property>
    <property name="hibernate.hbm2ddl.auto">create</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
    <property name="hibernate.dialect.storage_engine">innodb</property>
    <property name="hibernate.cache.use_second_level_cache">false</property>
  </session-factory>
</hibernate-configuration>

遗憾的是,hibernate仍然使用 engine=MyISAM !
我应该放在哪里 hibernate.dialect.storage_engine 属性,我找不到 hibernate.cfg.xml 来自官方网页!真烦人!
任何有效的联系将不胜感激。

vuktfyat

vuktfyat1#

将xml配置文件中的hibernate.dialect属性设置为mysql5dialect

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>

然后为应用程序设置jvm选项hibernate.dialect.storage\u engine=innodb。对于runnable jar,它将类似于:

java -Xmx4G -Dhibernate.dialect.storage_engine=innodb -jar application.jar

或者对于某些web应用程序容器(例如tomcat),添加

-Dhibernate.dialect.storage_engine=innodb

容器/web服务器的配置。

sd2nnvve

sd2nnvve2#

根据这个hhh问题,如果您想坚持使用 MySQL5Dialect .
或者,您可以切换到mysql55dialect innoDb 默认情况下:

public class MySQL55Dialect extends MySQL5Dialect {

        @Override
        protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
                return InnoDBStorageEngine.INSTANCE;
        }
}

相关问题