williem

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  1 随笔 :: 4 文章 :: 0 评论 :: 0 Trackbacks
(本文以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)  编辑  收藏 所属分类: 对象持久化

只有注册用户登录后才能发表评论。


网站导航: