hibernate整合druid

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="driverClassName">com.mysql.jdbc.Driver</property>
        <property name="url">*</property>
        <property name="username">*</property>
        <property name="password">*</property>
        <!-- 配置Hibernate的方言 -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- 可选配置================ -->
        <!-- 打印SQL -->
        <property name="hibernate.show_sql">true</property>
        <!-- 格式化SQL -->
        <property name="hibernate.format_sql">true</property>
        <!-- 自动创建表 -->
        <property name="hibernate.hbm2ddl.auto">update</property>





        <!-- 配置druid连接池 -->
        <property name="connection.provider_class">com.alibaba.druid.support.hibernate.DruidConnectionProvider
        </property>
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize">1</property>
        <property name="minIdle">1</property>
        <property name="maxActive">20</property>

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait">60000</property>

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis">60000</property>

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis">300000</property>

        <property name="validationQuery">SELECT 'x'</property>
        <property name="testWhileIdle">true</property>
        <property name="testOnBorrow">false</property>
        <property name="testOnReturn">false</property>

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements">true</property>
        <property name="maxPoolPreparedStatementPerConnectionSize">20</property>






        <mapping resource="Customer.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

如果使用了一下配置

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql:///hibernate_day01</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">abc</property>
那么会报错 druid初始化错误
相关文章
相关标签/搜索