Java

          Java

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            3 Posts :: 12 Stories :: 7 Comments :: 0 Trackbacks
          開發(fā)過(guò)程:
          1.建立三個(gè)表tb_topic,tb_reply,tb_manager

          CREATE TABLE `tb_topic` (
            `id` 
          int(10) unsigned NOT NULL AUTO_INCREMENT,
            `author` 
          varchar(20DEFAULT NULL,
            `face` 
          varchar(10DEFAULT NULL,
            `content` 
          text,
            `ip` 
          varchar(16DEFAULT NULL,
            `email` 
          varchar(100DEFAULT NULL,
            `createTime` 
          datetime DEFAULT NULL,
            
          PRIMARY KEY (`id`)
          ) ENGINE
          =MyISAM DEFAULT CHARSET=utf8;

          CREATE TABLE `tb_reply` (
            `id` 
          int(10) unsigned NOT NULL AUTO_INCREMENT,
            `topcid` 
          int(10DEFAULT NULL,
            `author` 
          varchar(20DEFAULT NULL,
            `content` 
          text,
            `createTime` 
          datetime DEFAULT NULL,
            
          PRIMARY KEY (`id`)
          ) ENGINE
          =MyISAM DEFAULT CHARSET=utf8;

          CREATE TABLE `tb_manager` (
            `id` 
          int(10) unsigned NOT NULL AUTO_INCREMENT,
            `name` 
          varchar(30DEFAULT NULL,
            `pwd` 
          varchar(30DEFAULT NULL,
            
          PRIMARY KEY (`id`)
          ) ENGINE
          =MyISAM DEFAULT CHARSET=utf8;


          2.建立hibernate配置文件

          <?xml version='1.0' encoding='UTF-8'?>
          <!DOCTYPE hibernate-configuration PUBLIC
                    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
          >

          <!-- Generated by MyEclipse Hibernate Tools.                   -->
          <hibernate-configuration>

          <session-factory>
              
          <property name="connection.username">root</property>
              
          <property name="connection.url">
                  jdbc:mysql://localhost:3306/test
              
          </property>
              
          <property name="dialect">
                  org.hibernate.dialect.MySQLDialect
              
          </property>
              
          <property name="myeclipse.connection.profile">mysql</property>
              
          <property name="connection.driver_class">
                  com.mysql.jdbc.Driver
              
          </property>
              
          <property name="show_sql">true</property>
              
          <property name="transaction.factory_class">
                  org.hibernate.transaction.JDBCTransactionFactory
              
          </property>


          </session-factory>

          </hibernate-configuration>

          3.創(chuàng)建實(shí)體類及其映射文件
          package com.actionForm;

          public class TopicForm {

              
          private int id = -1;
              
          private String author = "";
              
          private String face = "";
              
          private String content = "";
              
          private String ip = "";
              
          private String email = "";
              
          private String createTime = "";
              
              
          //getXXX() and setXXX()

          }

          TopicForm.hbm.xml
          <?xml version="1.0"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
          <hibernate-mapping>
              
          <class name="com.actionForm.TopicForm" table="tb_topic">

                  
          <id name="id" column="id" type="int">
                      
          <generator class="increment" /><!--設(shè)置自動(dòng)增值-->
                  
          </id>
                  
          <property name="author" column="author" type="string"
                      not-null
          ="true" />
                  
          <property name="face" column="face" type="string"
                      not-null
          ="true" />
                  
          <property name="content" column="content" type="string"
                      not-null
          ="true" />
                  
          <property name="ip" column="ip" type="string" not-null="true" />
                  
          <property name="email" column="email" type="string" />
                  
          <property name="createTime" column="createTime" type="string"
                      not-null
          ="true" />

              
          </class>
          </hibernate-mapping>


          package com.actionForm;

          public class ReplyForm {

              
          private int id = -1;
              
          private int topicid = -1;
              
          private String author = "";
              
          private String content = "";
              
          private String createTime = "";
              
              
          //getXXX() and setXXX()

          }

          ReplyForm.hbm.xml
          <?xml version="1.0"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
          <hibernate-mapping>
              
          <class name="com.actionForm.ReplyForm" table="tb_Reply">
                  
          <id name="id" column="id" type="int">
                      
          <generator class="increment" /><!--設(shè)置自動(dòng)增值-->
                  
          </id>
                  
          <property name="topicid" column="topicid" type="int"
                      not-null
          ="true" />
                  
          <property name="author" column="author" type="string" />
                  
          <property name="content" column="content" type="string" />
                  
          <property name="createTime" column="createTime" type="string" />
              
          </class>
          </hibernate-mapping>









          posted on 2008-11-23 22:45 keer 閱讀(350) 評(píng)論(0)  編輯  收藏 所屬分類: hibernate應(yīng)用開發(fā)

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 永昌县| 崇文区| 民县| 太白县| 达孜县| 拉萨市| 凤冈县| 昆山市| 贡嘎县| 公主岭市| 宣城市| 轮台县| 张家界市| 左云县| 海南省| 军事| 安图县| 湘乡市| 柳州市| 安徽省| 鱼台县| 郯城县| 新绛县| 尼勒克县| 泰兴市| 临猗县| 星座| 堆龙德庆县| 车险| 仲巴县| 台前县| 五河县| 冀州市| 镇雄县| 增城市| 湄潭县| 鸡泽县| 泰宁县| 贵定县| 武清区| 开封县|