隨筆:15 文章:206 評論:35 引用:0
fenglin
創(chuàng)新、創(chuàng)意、挑戰(zhàn)
C++博客
首頁
發(fā)新隨筆
發(fā)新文章
聯(lián)系
聚合
管理
hibernate 學(xué)習(xí)筆記之二 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
風(fēng)林
閱讀(96)
評論(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)站導(dǎo)航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
CALENDER
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
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
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
給我留言
查看公開留言
查看私人留言
隨筆分類
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)容較長,點擊標(biāo)題查看
--鄒
3.?re: ckeditor&ckfinder&s2sh集成
評論內(nèi)容較長,點擊標(biāo)題查看
--庸幾何
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ā)類工作了(501)
2.?給一家公司的軟件做加密方案(441)
3.?周一到周五都得出差,周末才能回(415)
4.?一流、二流、三流(406)
5.?最近工作有點忙(375)
評論排行榜
1.?周一到周五都得出差,周末才能回(2)
2.?給力2011(2)
3.?最近工作有點忙(0)
4.?生活(0)
5.?在博客園開博了(0)
Powered By:
博客園
模板提供
:
滬江博客
久久久久久亚洲精品不卡
|
亚洲国产精品无码久久
|
亚洲国产精品综合久久一线
|
国产麻豆精品久久一二三
|
人人妻久久人人澡人人爽人人精品
|
国产精品gz久久久
|
国产亚洲美女精品久久久久狼
|
偷窥少妇久久久久久久久
|
.精品久久久麻豆国产精品
|
一本色道久久99一综合
|
久久人人爽人人人人爽AV
|
亚洲午夜久久久
|
久久精品国产精品亚洲精品
|
中文成人久久久久影院免费观看
|
国产精品一久久香蕉产线看
|
久久久精品午夜免费不卡
|
99久久久精品
|
久久亚洲熟女cc98cm
|
日本一区精品久久久久影院
|
亚洲精品国产美女久久久
|
精品久久久久中文字幕一区
|
久久天天躁狠狠躁夜夜2020老熟妇
|
99久久夜色精品国产网站
|
久久久久亚洲AV无码永不
|
久久99国产精品久久99
|
色欲综合久久躁天天躁蜜桃
|
久久伊人中文无码
|
久久精品一区二区三区中文字幕
|
精品一区二区久久
|
99久久成人国产精品免费
|
亚洲国产精品无码久久一区二区
|
伊人久久大香线蕉成人
|
国产成人久久精品激情
|
亚洲精品无码成人片久久
|
亚洲精品综合久久
|
久久影院午夜理论片无码
|
久久久久久久国产免费看
|
国产精品99久久久久久www
|
99久久婷婷国产综合精品草原
|
久久久久久久久久久精品尤物
|
久久青青草原精品国产不卡
|