Hibernate 数据库连接总结

一.获取连接

4种方式:

1.hibernate内置的连接池(不用于生产环境,仅用来开发调试)

2.javax.sql.DataSource, 从JNDI获取,自动参与容器事务

3.hibernate默认支持的两种开源连接池c3p0和proxool

4.实现org.hibernate.service.jdbc.connections.spi.ConnectionProvider自定义的hibernate.connection.provider_class,例如使用其他的连接池

二.连接configuration

1.properties文件方式

2.xml文件方式

3.编程方式

4. java –Dproperty=value

三.数据源设置

重要的参数

  • hibernate.connection.driver_class

  • hibernate.connection.url

  • hibernate.connection.username

  • hibernate.connection.password

四.方言

自定义方言解析

实现org.hibernate.service.jdbc.dialect.spi.DialectResolver

并优先注册自定义的resolver

五.根据映射文件生成schema

java -cp hibernate_classpaths org.hibernate.tool.hbm2ddl.SchemaExport options mapping_files

 

你可能感兴趣的:(Hibernate 数据库连接总结)