依舊讓代碼站出來說話。。這是一個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略--*/
- }