//首先創(chuàng)建實(shí)體類(lèi) package cn.com.bochy.entity; public class hibernatebean { private long id; private String name; private String pwd; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } //然后 實(shí)體類(lèi)同包下新建類(lèi)名.hbm.xml 實(shí)體類(lèi)和數(shù)據(jù)表的映射文件 內(nèi)容如下 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <!-- package 是實(shí)體類(lèi)所對(duì)應(yīng)的完整包名 --> <hibernate-mapping package="cn.com.bochy.entity"> <!-- 對(duì)類(lèi)的配置 nane是實(shí)體類(lèi)名 table 是表名 可以不寫(xiě) 默認(rèn)與name的值一致 --> <class name="hibernatebean" table="t_user"> <!-- 對(duì)類(lèi)對(duì)應(yīng)的主鍵配置 name 是實(shí)體類(lèi)中主鍵屬性名 column 是表中主鍵對(duì)應(yīng)的列名 可以不寫(xiě) 默認(rèn)與namne的值一致 --> <id name="id" column="id"> <!-- 主鍵生成策略 native 如果連接的是oracle數(shù)據(jù)庫(kù) 則表示序列 ,并且序列的名字為為hibernate——sequence --> <generator class="native"/> </id> <!-- 對(duì)類(lèi)的非主鍵配置 --> <property name="name" column="name" type="string" unique="true" length="20"></property> <property name="pwd" column="pwd" type="string" length="20"></property> </class> </hibernate-mapping> //接下來(lái)新建hibernate配置文件 <?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> <session-factory> <!-- 數(shù)據(jù)庫(kù)連接設(shè)置 --> <!-- Database connection settings --> <property name="connection.driver_class"> oracle.jdbc.OracleDriver </property <property name="connection.url"> jdbc:oracle:thin:@admini-PC.mshome.net:1521:orcl </property> <property name="connection.username">scott</property> <property name="connection.password">scott</property> <!-- sql方言 --> <!-- SQL dialect --> <property name="dialect"> org.hibernate.dialect.OracleDialect </property> <!-- 顯示sql語(yǔ)句 --> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!--將顯示的sql語(yǔ)句按一定的格式 顯示出來(lái) --> <property name="format_sql">true</property> <!-- ddl(數(shù)據(jù)定義語(yǔ)言)的配置 --> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <!-- 配置讀取的映射文件 --> <mapping resource="cn/com/bochy/entity/hibernate_HelloWorld.hbm.xml" /> <!-- ddl(數(shù)據(jù)定義語(yǔ)言)的配置 --> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <!-- 配置讀取的數(shù)據(jù)庫(kù)映射文件 --> <mapping resource="cn/com/bochy/entity/hibernate_HelloWorld.hbm.xml" /> </session-factory> </hibernate-configuration>
網(wǎng)站欄目:hibernatexml配置
轉(zhuǎn)載來(lái)源:http://muchs.cn/article20/jehdco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、服務(wù)器托管、外貿(mào)建站、網(wǎng)站改版、網(wǎng)站維護(hù)、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)