Hibernate 01 配置檔案

2022-09-16 06:45:07 字數 1337 閱讀 3616

hibernate 配置檔案(此內容用於新手上路)

hibernate配置檔案支援兩種形式,一種是xml格式的配置檔案,另一種是j**a屬性檔案格式的配置檔案,採用「鍵值」的形式。建議採用xml格式的配置檔案。xml配置檔案可以直接巴對對映檔案進行配置,並由hibernate自動載入,而properties檔案則必須在程式中通過編碼載入對映檔案。hibernate給人的感受是靈活的,要達到同乙個目的,可以任選其一使用。 

注意:(建立hibernate.cfg.xml時,名字一定要相同不然的話,會報錯)

方法2、建立j**a屬性檔案格式的配置檔案,將hibernate.properties放置放 在類路徑的根目錄下。 

1.建立xml格式的配置檔案(oracle)

1,配置hibernate.cfg.xml

<?xml version="

1.0" encoding="

utf-8

"?>

configuration public

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

">

"connection.driver_class

">oracle.jdbc.driver.oracledriver

"connection.url

">jdbc:oracle:thin:@localhost:1521:orcl

"connection.username

">scott

"connection.password

">111222

"dialect

">org.hibernate.dialect.oracle10gdialect

"hbm2ddl.auto

">create

"show_sql

">true

"format_sql

">true

" />

2,建立實體類

package entity;

public

class

student

public

void

setsno(string sno)

public

string getsname()

public

void

setsname(string sname)

}

3.建立對映檔案

<?xml version="1.0" encoding="utf-8"?>

(未完)

hibernate01 概念 正向工程 反向工程

第一 概念 19.查詢可以不用事務,因為查詢對資料庫沒有影響。20.get是單條查詢,load也是單條查詢 21.hibernate seqence.nextval 22.查詢query,criteria 23.分頁 setmaxresult 每頁有幾個,setfirstresult 起始頁。預設資...

Hibernate的配置檔案配置

hiebernate一共有兩種方式,xml檔案配置和注釋配置,這裡就只講第一種配置方式 xml配置檔案配置,而xml檔案配置需要配置兩個檔案,分別是hibernate.cfg.xml和 hbm.xml 這個 是和實體類名一樣的,例如customer的實體類,如下 public class custo...

Hibernate的配置檔案

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