Hibernate的配置檔案配置

2021-10-05 22:27:07 字數 2608 閱讀 2257

hiebernate一共有兩種方式,xml檔案配置和注釋配置,這裡就只講第一種配置方式-xml配置檔案配置,而xml檔案配置需要配置兩個檔案,分別是hibernate.cfg.xml和***.hbm.xml

這個***是和實體類名一樣的,例如customer的實體類,**如下

public

class

customer

public

void

setid

(int id)

public string getname()

public

void

setname

(string name)

public string getaddress()

public

void

setaddress

(string address)

}

則customer.hbm.xml的**如下:

<

?xml version=

"1.0" encoding=

"utf-8"

?>

<

>

<

!-- name是實體類的全名

table是表的名稱

catalog是資料庫的名稱

-->

<

class

name

="hibernate.yu.domain.customer" table=

"t_customer" catalog=

"hibernate"

>

<

!--id是用於描述主鍵的--

>

"id" column=

"id"

>

="native"

>

<

/generator>

<

/id>

<

!--使用property來描述屬性與字段--

>

"name" column=

"name"

>

<

/property>

"address" column=

"address"

>

<

/property>

<

/class

>

<

**如下:

<

?xml version=

"1.0" encoding=

"utf-8"

?>

<

!doctype hibernate-configuration public

"-//hibernate/hibernate configuration dtd 3.0//en"

"">

<

!--配置關於資料庫連線的四個項 driveclass url username password--

>

"hibernate.connection.driver_class"

>com.mysql.jdbc.driver<

/property>

"hibernate.connection.url"

>jdbc:mysql:

///hibernate

"hibernate.connection.username"

>root<

/property>

"hibernate.connection.password"

>

123456

<

/property>

<

!--可以將向資料庫傳送的語句顯示出來--

>

"hibernate.show_sql"

>

true

<

/property>

<

!--格式化sql--

>

"hibernate.format_sql"

>

true

<

/property>

<

!--hibernate的方言--

>

"hibernate.dialect"

>org.hibernate.dialect.mysqldialect<

/property>

<

!--自動建表--

>

"hibernate.hbm2ddl.auto"

>update<

/property>

<

!--配置hibernate的對映檔案所在位置--

>

"hibernate/yu/domain2/customer.hbm.xml"

/>

"hibernate/yu/domain2/order.hbm.xml"

/>

<

/session-factory>

<

/hibernate-configuration>

Hibernate的配置檔案

必選項 hibernate.connection.username 訪問的資料庫使用者名稱 hibernate.connection.password 訪問的資料庫密碼 hibernate.connection.url 連線資料庫的url hibernate.connection.driver cl...

Hibernate的配置檔案

對ehibernate的核心配置檔案可以有兩種 hibernate.cfg.xml hibernate.properties 編碼實現 configuration config new configuration addresource hbm.xml 核心配置檔案hibernate.cfg.xml...

Hibernate主配置檔案

主配置hibernate.cfg.xml 一.配置的key前面的hibernate.字首可有可無 二.按作用分為三類 1.資料庫資訊 五個配置資訊 方言 驅動 url username password org.hibernate.dialect.mysqldialect jdbc mysql hi...