hibernate入门笔记

如何使用

导入依赖
<dependencies>
 <dependency>
 <groupId>mysqlgroupId>
 <artifactId>mysql-connector-javaartifactId>
 <version>8.0.19version>
 dependency>
 <dependency>
 <groupId>org.hibernategroupId>
 <artifactId>hibernate-coreartifactId>
 <version>5.4.10.Finalversion>
 dependency>
 <dependency>
 <groupId>org.projectlombokgroupId>
 <artifactId>lombokartifactId>
 <version>1.18.10version>
 dependency>
dependencies>
创建hibernate配置文件

SessionFactory:针对单个数据库映射经过编译的内存镜像⽂件,将数据库转换为⼀个 Java 可以识别的镜像⽂件。
构建 SessionFactory ⾮常耗费资源,所以通常⼀个⼯程只需要创建⼀个 SessionFactory。


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.username">rootproperty>
 <property name="connection.password">rootproperty>
 <property
name="connection.driver_class">com.mysql.cj.jdbc.Driverproperty>
 <property name="connection.url">jdbc:mysql://localhost:3306/test?
useUnicode=true&characterEncoding=UTF-8property>
 
 <property name="hibernate.c3p0.acquire_increment">10property>
 <property name="hibernate.c3p0.idle_test_period">10000property>
 <property name="hibernate.c3p0.timeout">5000property>
 <property name="hibernate.c3p0.max_size">30property>
 <property name="hibernate.c3p0.min_size">5property>
 <property name="hibernate.c3p0.max_statements">10property>
 
 <property name="dialect">org.hibernate.dialect.MySQLDialectproperty>
 
 <property name="show_sql">trueproperty>
 
 <property name="format_sql">trueproperty>
 
 <property name="hibernate.hbm2ddl.auto">property>
 session-factory>
hibernate-configuration>

你可能感兴趣的:(java杂文,hibernate,笔记,java)