williem
BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
::
1 随笔 :: 4 文章 :: 0 评论 :: 0 Trackbacks
<
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
常用链接
我的随笔
我的评论
我的参与
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2006年6月 (1)
文章分类
Web报表类(1)
(rss)
对象持久化(6)
(rss)
标签类(2)
(rss)
文章档案
2006年12月 (1)
2006年6月 (3)
相册
ProgramImg
搜索
最新评论
Hibernate应用的必要配置
(本文以Hibernate3为蓝本)
1 必要的jar文件
antlr-2.7.6rc1.jar
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ehcache-1.1.jar
hibernate3.jar
jdbc2_0-stdext.jar
jgroups-2.2.8.jar
jta.jar
log4j-1.2.11.jar
xml-apis.jar
以上文件可以从
http://www.hibernate.org/
中得到。解压数据包后复制到项目的lib下面。
2 Hibernate的配置文件
2.1 hibernate.cfg.xml是hibernate的主要配置文件内容如下
1
<?
xml version="1.0"
?>
2
<!
DOCTYPE hibernate-configuration
3
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
4
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>
5
6
<
hibernate-configuration
>
7
<
session-factory
>
8
<!--
property name="connection.datasource">
9
java:comp/env/jdbc/sgbc
10
</property
-->
11
<
property
name
="dialect"
>
12
org.hibernate.dialect.MySQLDialect
13
</
property
>
14
<
property
name
="show_sql"
>
15
false
16
</
property
>
17
<
property
name
="connection.driver_class"
>
18
com.mysql.jdbc.Driver
19
</
property
>
20
<
property
name
="connection.url"
>
21
jdbc:mysql://localhost:3306/sgbc
22
</
property
>
23
<
property
name
="connection.username"
>
24
username
25
</
property
>
26
<
property
name
="connection.password"
>
27
123456
28
</
property
>
29
<
mapping
resource
="Test.hbm.xml"
/>
30
<
mapping
resource
="Item.hbm.xml"
/>
31
<
mapping
resource
="Customer.hbm.xml"
/>
32
</
session-factory
>
33
</
hibernate-configuration
>
34
2.2 对象映射配置文件-有一个持久对象映射就有一个配置文件以xxx.hbm.xml为文件名。以下是一个例子
1
<?
xml version="1.0" encoding="GB2312"
?>
2
<!
DOCTYPE hibernate-mapping PUBLIC
3
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
4
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
5
6
<
hibernate-mapping
>
7
<
class
name
="com.sgbc.hibernate.Item"
8
table
="item"
9
>
10
<
id
name
="iid"
11
column
="iid"
>
12
<
generator
class
="identity"
/>
13
</
id
>
14
15
<
property
name
="fields"
>
16
<
column
name
="fields"
17
/>
18
</
property
>
19
20
<
property
name
="tid"
column
="tid"
/>
21
22
</
class
>
23
24
</
hibernate-mapping
>
posted on 2006-06-20 09:17
阔阔
阅读(165)
评论(0)
编辑
收藏
所属分类:
对象持久化
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
BlogJava
Copyright © 阔阔