java 需要 mysql 的休眠属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3270105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:04:57  来源:igfitidea点击:

Need hibernate properties for mysql

javahibernatespring

提问by Blankman

I can't seem to find an example of hibernate properties for mysql.

我似乎找不到 mysql 的休眠属性示例。

Is there a link that has an example?

有没有例子的链接?

I have one for hsql:

我有一个用于 hsql:

<!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--<property name="configLocation" value="classpath:hibernate.cfg.xml"/>      -->
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.HSQLDialect
                hibernate.query.substitutions=true 'Y', false 'N'
                hibernate.cache.use_query_cache=true
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
                hibernate.jdbc.batch_size=0
            </value>
        </property>
    </bean>

回答by Romain Hippeau

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="connection.url">jdbc:mysql://localhost/firsthibernate</property>
    <property name="connection.username">root</property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="connection.password">r</property>
 <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <!--  thread is the short name for
      org.hibernate.context.ThreadLocalSessionContext
      and let Hibernate bind the session automatically to the thread
    -->
    <property name="current_session_context_class">thread</property>
    <!-- this will show us all sql statements -->
    <property name="hibernate.show_sql">true</property>

    <!-- mapping files -->
    <mapping resource="de/laliluna/example/Honey.hbm.xml" />

</session-factory>
</hibernate-configuration>

回答by Ross

Based on your current Spring config file I think it would be:

根据您当前的 Spring 配置文件,我认为它将是:

<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <!--<property name="configLocation" value="classpath:hibernate.cfg.xml"/>      -->
        <property name="hibernateProperties">
                <value>
                        hibernate.dialect=org.hibernate.dialect.MySQLDialect
                        hibernate.connection.url=jdbc:mysql://localhost/mydb
                        hibernate.connection.username=dbuser
                        hibernate.connection.password=dbpass
                        hibernate.query.substitutions=true 'Y', false 'N'
                        hibernate.cache.use_query_cache=true
                        hibernate.cache.use_second_level_cache=true
                        hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
                        hibernate.jdbc.batch_size=0
                </value>
        </property>
</bean>