Hibernate中的不同主键生成策略下flush()方法的妙用
依旧让代码站出来说话。。这是一个Java Project。。
首先是位于src下的Hibernate核心配置文件hibernate.cfg.xml
- <?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="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="connection.url">jdbc:mysql://localhost:3306/jadyer?characterEncoding=UTF-8</property>
- <property name="connection.username">root</property>
- <property name="connection.password">jadyer</property>
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.show_sql">true</property>
- <property name="hibernate.format_sql">true</property>
- <!-- 批量读取数据。建议值50。需要JDBC和底层数据库的支持 -->
- <property name="hibernate.jdbc.fetch_size">50</property>
- <!-- 批量更新数据。建议值30 -->
- <property name="hibernate.jdbc.batch_size">30</property>
- <!-- 配置完这两个属性后,当我们向数据库提交SQL时,就不会一次性把全部数据读入内存 -->
- <!-- 而是按照一定的数量来批量读取相应的数据,但最终是否会生效还取决于底层数据库的支持 -->
- <!-- 有些数据库就不支持这些参数。其中Oracle和SQLServer都支持,而MySQL貌似就不支持 -->
- <!-- 也可以通过以下方式编写映射文件 -->
- <mapping resource="com/jadyer/hibernate/all.hbm.xml"/>
- <!--
- <mapping resource="com/jadyer/hibernate/User11.hbm.xml"/>
- <mapping resource="com/jadyer/hibernate/User22.hbm.xml"/>
- <mapping resource="com/jadyer/hibernate/User33.hbm.xml"/>
- -->
- </session-factory>
- </hibernate-configuration>
接下来是我们用到的三个实体类
- package com.jadyer.hibernate;
- import java.util.Date;
- public class User11 {
- private String id;
- private String name;
- private String password;
- private Date createTime;
- /*--三个属性对应的setter和getter略--*/
- }
- package com.jadyer.hibernate;
- import java.util.Date;
- public class User22 {
- private int id;
- private String name;
- private String password;
- private Date createTime;
- /*--三个属性对应的setter和getter略--*/
- }
- package com.jadyer.hibernate;
- import java.util.Date;
- public class User33 {
- private String id;
- private String name;
- private String password;
- private Date createTime;
- /*--三个属性对应的setter和getter略--*/
- }
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20