隨筆:15 文章:206 評論:35 引用:0
fenglin
創(chuàng)新、創(chuàng)意、挑戰(zhàn)
C++博客
首頁
發(fā)新隨筆
發(fā)新文章
聯(lián)系
聚合
管理
hibernate 學習筆記之二 Hello World
包括以下三個必須文件和一個測試用例文件:
Student.java
1
2
package
com.bebig.hibernate.model;
3
4
/** */
/**
5
*
@author
fenglin
6
* @filename Student.java
7
*/
8
public
class
Student
{
9
private
int
id;
10
11
public
int
getId()
{
12
return
id;
13
}
14
15
public
void
setId(
int
id)
{
16
this
.id
=
id;
17
}
18
19
public
String getName()
{
20
return
name;
21
}
22
23
public
void
setName(String name)
{
24
this
.name
=
name;
25
}
26
27
public
int
getAge()
{
28
return
age;
29
}
30
31
public
void
setAge(
int
age)
{
32
this
.age
=
age;
33
}
34
35
private
String name;
36
private
int
age;
37
38
}
39
Student.hbm.xml,保存到與上一個文件同一文件夾(推薦)
1
<!--
filename:Student.hbm.xml
-->
2
<?
xml version="1.0"
?>
3
<!
DOCTYPE hibernate-mapping PUBLIC
4
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
5
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
6
7
<
hibernate-mapping
package
="com.bebig.hibernate.model"
>
8
<
class
name
="Student"
>
9
<
id
name
="id"
>
10
<!--
<generator class="native" />
-->
11
</
id
>
12
<
property
name
="name"
></
property
>
13
<
property
name
="age"
></
property
>
14
</
class
>
15
</
hibernate-mapping
>
hibernate.cfg.xml,保存到與src文件夾里:
1
<!--
filename:hibernate.cfg.xml
-->
2
<?
xml version='1.0' encoding='utf-8'
?>
3
<!
DOCTYPE hibernate-configuration PUBLIC
4
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
5
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>
6
7
<
hibernate-configuration
>
8
9
<
session-factory
>
10
11
<!--
Database connection settings
-->
12
<
property
name
="connection.driver_class"
>
com.microsoft.sqlserver.jdbc.SQLServerDriver
</
property
>
13
<
property
name
="connection.url"
>
jdbc:sqlserver://localhost:1433;DatabaseName=hibernate
</
property
>
14
<
property
name
="connection.username"
>
sa
</
property
>
15
<
property
name
="connection.password"
>
********
</
property
>
16
17
<!--
JDBC connection pool (use the built-in)
-->
18
<!--
<property name="connection.pool_size">1</property>
-->
19
20
<!--
SQL dialect
-->
21
<
property
name
="dialect"
>
org.hibernate.dialect.SQLServerDialect
</
property
>
22
23
<!--
Enable Hibernate's automatic session context management
-->
24
<!--
<property name="current_session_context_class">thread</property>
-->
25
26
<!--
Disable the second-level cache
-->
27
<
property
name
="cache.provider_class"
>
org.hibernate.cache.NoCacheProvider
</
property
>
28
29
<!--
Echo all executed SQL to stdout
-->
30
<
property
name
="show_sql"
>
true
</
property
>
31
<
property
name
="format_sql"
>
true
</
property
>
32
33
<!--
Drop and re-create the database schema on startup
-->
34
<
property
name
="hbm2ddl.auto"
>
create
</
property
>
35
36
<
mapping
resource
="com/bebig/hibernate/model/Student.hbm.xml"
/>
37
38
</
session-factory
>
39
40
</
hibernate-configuration
>
測試用例:StudentTest.java
1
import
org.hibernate.Session;
2
import
org.hibernate.SessionFactory;
3
import
org.hibernate.cfg.Configuration;
4
5
import
com.bebig.hibernate.model.Student;
6
7
8
public
class
StudentTest
{
9
public
static
void
main(String[] args)
{
10
Student s
=
new
Student();
11
s.setId(
2
);
12
s.setName(
"
Don
"
);
13
s.setAge(
26
);
14
15
Configuration cfg
=
new
Configuration();
16
SessionFactory sf
=
cfg.configure().buildSessionFactory();
17
Session session
=
sf.openSession();
18
session.beginTransaction();
19
session.save(s);
20
session.getTransaction().commit();
21
22
session.close();
23
sf.close();
24
}
25
}
26
發(fā)表于 2010-09-22 15:57
風林
閱讀(100)
評論(0)
編輯
收藏
引用
所屬分類:
JAVA
、
Hibernate
只有注冊用戶
登錄
后才能發(fā)表評論。
【推薦】100%開源!大型工業(yè)跨平臺軟件C++源碼提供,建模,組態(tài)!
相關(guān)文章:
[轉(zhuǎn)]java編程中'為了性能'一些盡量做到的地方
JAVAC命令行錯誤
Java基礎(chǔ)_Collection接口下的子類存儲特性
Android_常用控件使用
Android_Activity&Intent&Layout
Integer自動裝箱、拆箱問題
自定義比較器、排序
JDBC操作實例
常用數(shù)據(jù)庫的JDBC連接代碼
[轉(zhuǎn)]J2SE_內(nèi)部類
網(wǎng)站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
CALENDER
<
2025年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
jBPM
(rss)
隨筆檔案
2011年7月 (1)
2011年4月 (1)
2011年2月 (1)
2010年11月 (1)
2010年10月 (2)
2010年9月 (3)
2010年8月 (4)
2010年7月 (2)
文章分類
AJAX(2)
(rss)
Android(2)
(rss)
C#(20)
(rss)
C++(6)
(rss)
ckeditor&ckfinder(1)
(rss)
CSS
(rss)
Delphi(2)
(rss)
Hibernate(39)
(rss)
JAVA(95)
(rss)
jQuery(1)
(rss)
JSP(9)
(rss)
Maven(1)
(rss)
MySQL(4)
(rss)
OOP(1)
(rss)
Python(42)
(rss)
Spring(31)
(rss)
SQL Server(4)
(rss)
Struts2(35)
(rss)
SVN(1)
(rss)
Tomcat(1)
(rss)
Ubuntu(1)
(rss)
軟件加解密技術(shù)
(rss)
雜文(1)
(rss)
文章檔案
2011年8月 (1)
2011年7月 (3)
2011年6月 (19)
2011年5月 (2)
2011年4月 (1)
2011年2月 (1)
2010年12月 (2)
2010年11月 (21)
2010年10月 (67)
2010年9月 (48)
2010年8月 (37)
2010年7月 (4)
新聞檔案
2010年7月 (1)
相冊
CSS
Hibernate
搜索
最新評論
1.?re: Struts2_三種傳參數(shù)方法
方式的發(fā)生
--阿飛史蒂夫
2.?re: 在Win7上搭建JSP開發(fā)環(huán)境
評論內(nèi)容較長,點擊標題查看
--鄒
3.?re: ckeditor&ckfinder&s2sh集成
評論內(nèi)容較長,點擊標題查看
--庸幾何
4.?re: 在Win7上搭建JSP開發(fā)環(huán)境
下個 myeclipse@lou
--孫毅
5.?re: 在Win7上搭建JSP開發(fā)環(huán)境
@lou
運行 -cmd 找到startup.bat 在java 環(huán)境中運行
--孫毅
閱讀排行榜
1.?開始找Java開發(fā)類工作了(510)
2.?給一家公司的軟件做加密方案(443)
3.?一流、二流、三流(421)
4.?周一到周五都得出差,周末才能回(420)
5.?最近工作有點忙(381)
評論排行榜
1.?周一到周五都得出差,周末才能回(2)
2.?給力2011(2)
3.?最近工作有點忙(0)
4.?生活(0)
5.?在博客園開博了(0)
Powered By:
博客園
模板提供
:
滬江博客
日日狠狠久久偷偷色综合免费
|
国产精品热久久毛片
|
亚洲AV无码1区2区久久
|
亚洲欧洲久久久精品
|
一本一本久久a久久精品综合麻豆
|
久久久国产视频
|
精品熟女少妇av免费久久
|
久久91精品综合国产首页
|
亚洲国产一成人久久精品
|
精品久久无码中文字幕
|
久久免费国产精品
|
国产精品禁18久久久夂久
|
婷婷伊人久久大香线蕉AV
|
aaa级精品久久久国产片
|
久久无码一区二区三区少妇
|
亚洲愉拍99热成人精品热久久
|
一级做a爱片久久毛片
|
国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞
|
久久99精品久久久久久久不卡
|
精品人妻伦九区久久AAA片69
|
久久久久久精品免费看SSS
|
88久久精品无码一区二区毛片
|
久久亚洲AV成人无码软件
|
国产午夜福利精品久久
|
久久久久久亚洲精品成人
|
欧美麻豆久久久久久中文
|
久久免费小视频
|
国产精品一久久香蕉产线看
|
72种姿势欧美久久久久大黄蕉
|
2021国产精品久久精品
|
久久综合视频网站
|
人妻无码精品久久亚瑟影视
|
99久久国产综合精品成人影院
|
国产精品久久久福利
|
久久久久久久99精品免费观看
|
精品久久一区二区三区
|
久久精品一区二区
|
久久99精品国产麻豆宅宅
|
亚洲午夜久久影院
|
精品多毛少妇人妻AV免费久久
|
精品国产青草久久久久福利
|