隨筆: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:
博客園
模板提供
:
滬江博客
97久久国产综合精品女不卡
|
波多野结衣久久一区二区
|
午夜不卡久久精品无码免费
|
午夜精品久久久久久久
|
久久精品成人国产午夜
|
国产精品熟女福利久久AV
|
久久久久无码中
|
久久精品国产久精国产果冻传媒
|
伊人久久大香线蕉综合影院首页
|
Xx性欧美肥妇精品久久久久久
|
国产综合免费精品久久久
|
精品久久亚洲中文无码
|
激情久久久久久久久久
|
亚洲精品无码成人片久久
|
久久综合九色综合久99
|
国产A级毛片久久久精品毛片
|
国产精品一区二区久久
|
一本大道久久a久久精品综合
|
一级做a爱片久久毛片
|
久久久久国产精品人妻
|
久久丫精品国产亚洲av不卡
|
久久精品9988
|
久久精品麻豆日日躁夜夜躁
|
久久久久97国产精华液好用吗
|
久久天天躁狠狠躁夜夜躁2O2O
|
久久人人爽人人澡人人高潮AV
|
久久久久亚洲AV成人网人人网站
|
色噜噜狠狠先锋影音久久
|
精品久久久中文字幕人妻
|
日韩精品无码久久一区二区三
|
国产精品美女久久久久网
|
久久久久亚洲AV片无码下载蜜桃
|
91久久成人免费
|
国产精品久久久久影院嫩草
|
中文字幕日本人妻久久久免费
|
久久只有这里有精品4
|
久久国产成人午夜aⅴ影院
|
99久久精品久久久久久清纯
|
久久精品国产影库免费看
|
久久久久久久99精品免费观看
|
久久免费视频网站
|