1. 程式人生 > >Hibernate配置資訊

Hibernate配置資訊

 hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<!-- 先配置sessionFactory標籤 一個數據庫對應一個sessionFactory標籤 -->
	<session-factory>
		<!-- 必須配置的五個引數 -->
		<!-- 四大引數 -->
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql:///hibernate_day01</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.connection.password">123456</property>
		<!-- 資料庫的方言 -->
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

		<!-- 可選配置 -->
		<!-- 顯示SQL語句 -->
		<property name="hibernate.show_sql">true</property>
		<!-- SQL語句格式化 -->
		<property name="hibernate.format_sql">true</property>

		<!-- 生成資料庫的表結構<property name="hibernate.hbm2ddl.auto">create</property> -->

		<!-- 對映配置檔案,需要引入對映的配置檔案 -->
		<mapping resource="com/lingnet/domain/Customer.hbm.xml" />
	</session-factory>
</hibernate-configuration>

 對映檔案配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
	<class name="com.lingnet.domain.Customer" table="cst_customer">
		<id name="cust_id" column="cust_id">
			<!-- 主鍵生成策略 -->
			<generator class="native" />
		</id>
		<!-- 配置其他屬性 -->
		<property name="cust_name" column="cust_name" />
		<property name="cust_user_id" column="cust_user_id" />
		<property name="cust_create_id" column="cust_create_id" />
		<property name="cust_source" column="cust_source" />
		<property name="cust_industry" column="cust_industry" />
		<property name="cust_level" column="cust_level" />
		<property name="cust_linkman" column="cust_linkman" />
		<property name="cust_phone" column="cust_phone" />
		<property name="cust_mobile" column="cust_mobile" />

	</class>
</hibernate-mapping>