正在阅读:Hibernate初体验Cat之快速上手Hibernate初体验Cat之快速上手

2004-09-07 10:04 出处:CSDN 作者:ahxu 责任编辑:linjixiong


  public void setSex(char sex) {
  this.sex = sex;
  }

  public float getWeight() {
  return weight;
  }

  public void setWeight(float weight) {
  this.weight = weight;
  }

  }

 

  3) 将以下代码保存为O/R映射文件Cat.hbm.xml,放入%WebApp%/WEB-INF/classes


  <?xml version="1.0"?>
  <!DOCTYPE hibernate-mapping
  PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
  <hibernate-mapping>
  <class name="net.sf.hibernate.examples.quickstart.Cat" table="CAT">
  <!-- A 32 hex character is our surrogate key. It's automatically
  generated by Hibernate with the UUID pattern. -->
  <id name="id" type="string" unsaved-value="null" >
  <column name="CAT_ID" sql-type="char(32)" not-null="true"/>
  <generator class="uuid.hex"/>
  </id>
  <!-- A cat has to have a name, but it shouldn' be too long. -->
  <property name="name">
  <column name="NAME" length="16" not-null="true"/>
  </property>
  <property name="sex"/>
  <property name="weight"/>
  </class>
  </hibernate-mapping


  

  4) 在数据库内建表,结构如下

  Column |         Type          | Modifiers
  --------+-----------------------+-----------
  cat_id | character(32)         | not null
  name   | character varying(16) | not null
  sex    | character(1)          |
  weight | real                  |
  Indexes: cat_pkey primary key btree (cat_id)
  





察看评论详细内容 我要发表评论
作者笔名简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品