时间:2021-07-01 10:21:17 帮助过:29人阅读
<property name="hibernate.connection.provider_class"> com.alibaba.druid.support.hibernate.DruidConnectionProvider </property> <property name="driverClassName">com.mysql.jdbc.Driver</property> <property name="url"> jdbc:mysql://127.0.0.1:3306/hibernate?useSSL=true </property> <property name="username">admin</property> <property name="password">123456</property> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize">5</property> <property name="minIdle">5</property> <property name="maxActive">100</property> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait">60000</property> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis">60000</property> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis">300000</property> <!-- 打开PSCache,并且指定每个连接上PSCache的大小 --> <property name="poolPreparedStatements">true</property> <property name="maxPoolPreparedStatementPerConnectionSize">20</property> <!-- 配置监控统计拦截的filters,去掉后监控界面sql无法统计 --> <property name="filters">stat</property> <!-- JDBC connection pool (use the built-in) --> <!-- <property name="connection.pool_size">5</property> --> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <!-- Enable Hibernate‘s automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">false</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <mapping resource="com/synpower/entity/ModeDetailModbus.hbm.xml" />
首先说我的4.3版本的创建方法
try{ Configuration conf = new Configuration().configure(); StandardServiceRegistry standardServiceRegistry = new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build(); factory = conf .buildSessionFactory(standardServiceRegistry); }catch(Exception e){ System.out.println("init factory error"+e.getMessage()); }
其他版本可以自行百度 ,参考地址:http://yanln.iteye.com/blog/2249939
Hibernate整合Druid数据库连接池遇到的问题整合
标签:org 1.0 prepare post service 阿里巴巴 ons 3.3 数据库