本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7583468
建立时间:2006年5月29日




[Hibernate]Hibernate 调用带有复合主键的stored procedure
软件技术,  电脑与网络

lhwork 发表于 2006/6/28 11:12:58

Mapping file:<?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><!--   Created by the Middlegen Hibernate plugin 2.1   http://boss.bekk.no/boss/middlegen/  http://www.hibernate.org/--> <class name="con.lalfa.hibernate.hibernate.TestTable"   table="TestTable" >   <meta attribute="class-description" inherit="false">    @hibernate.class    table="TestTable"  </meta>   <composite-id name="comp_id" class="con.lalfa.hibernate.hibernate.TestTablePK">    <meta attribute="field-description" inherit="false">      @hibernate.id      generator-class="assigned"    </meta>    <key-property       name="keyDate"       column="keyDate"       type="java.sql.Timestamp"      length="23"    >      <meta attribute="field-description"> @hibernate.property column="keyDate"      </meta>     </key-property>    <key-property       name="keyString"       column="keyString"       type="java.lang.String"      length="50"    >      <meta attribute="field-description"> @hibernate.property column="keyString"      </meta>     </key-property>    <key-property       name="keyInt"       column="keyInt"       type="java.lang.Integer"      length="10"    >      <meta attribute="field-description"> @hibernate.property column="keyInt"      </meta>     </key-property>  </composite-id>     <property    name="conteng"    type="java.lang.String"    column="conteng"    length="200"  >    <meta attribute="field-description">      @hibernate.property      column="conteng"      length="200"    </meta>    </property>   <!-- Associations -->  <!-- derived association(s) for compound key -->  <!-- end of derived association(s) -->   <loader query-ref="selectAllValues_SP"></loader></class><sql-query name="selectAllValues_SP" callable="true">  <return alias="testTable" class="con.lalfa.hibernate.hibernate.TestTable">    <return-property name="comp_id">       <return-column name="keyDate"/>      <return-column name="keyString"/>      <return-column name="keyInt"/>    </return-property>    <return-property name="conteng" column="conteng"/>  </return>  {call selectAllValues}</sql-query></hibernate-mapping>java class:TestTable.javapackage con.lalfa.hibernate.hibernate; import java.io.Serializable;import org.apache.commons.lang.builder.EqualsBuilder;import org.apache.commons.lang.builder.HashCodeBuilder;import org.apache.commons.lang.builder.ToStringBuilder; /**  *    @hibernate.class *     table="TestTable" *   */public class TestTable implements Serializable {   /** identifier field */  private con.lalfa.hibernate.hibernate.TestTablePK comp_id;   /** nullable persistent field */  private String conteng;   /** full constructor */  public TestTable(con.lalfa.hibernate.hibernate.TestTablePK comp_id, String conteng) {    this.comp_id = comp_id;    this.conteng = conteng;  }   /** default constructor */  public TestTable() {  }   /** minimal constructor */  public TestTable(con.lalfa.hibernate.hibernate.TestTablePK comp_id) {    this.comp_id = comp_id;  }   /**    *      @hibernate.id   *       generator-class="assigned"   *        */  public con.lalfa.hibernate.hibernate.TestTablePK getComp_id() {    return this.comp_id;  }   public void setComp_id(con.lalfa.hibernate.hibernate.TestTablePK comp_id) {    this.comp_id = comp_id;  }   /**    *      @hibernate.property   *       column="conteng"   *       length="200"   *        */  public String getConteng() {    return this.conteng;  }   public void setConteng(String conteng) {    this.conteng = conteng;  }   public String toString() {    return new ToStringBuilder(this)      .append("comp_id", getComp_id())      .toString();  }   public boolean equals(Object other) {    if ( !(other instanceof TestTable) ) return false;    TestTable castOther = (TestTable) other;    return new EqualsBuilder()      .append(this.getComp_id(), castOther.getComp_id())      .isEquals();  }   public int hashCode() {    return new HashCodeBuilder()      .append(getComp_id())      .toHashCode();  } }TestTablePK.java:package con.lalfa.hibernate.hibernate; import java.io.Serializable;import java.util.Date;import org.apache.commons.lang.builder.EqualsBuilder;import org.apache.commons.lang.builder.HashCodeBuilder;import org.apache.commons.lang.builder.ToStringBuilder; /** @author Hibernate CodeGenerator */public class TestTablePK implements Serializable {   /** identifier field */  private Date keyDate;   /** identifier field */  private String keyString;   /** identifier field */  private Integer keyInt;   /** full constructor */  public TestTablePK(Date keyDate, String keyString, Integer keyInt) {    this.keyDate = keyDate;    this.keyString = keyString;    this.keyInt = keyInt;  }   /** default constructor */  public TestTablePK() {  }   /**    * @hibernate.property   *  column="keyDate"   *          */  public Date getKeyDate() {    return this.keyDate;  }   public void setKeyDate(Date keyDate) {    this.keyDate = keyDate;  }   /**    * @hibernate.property   *  column="keyString"   *          */  public String getKeyString() {    return this.keyString;  }   public void setKeyString(String keyString) {    this.keyString = keyString;  }   /**    * @hibernate.property   *  column="keyInt"   *          */  public Integer getKeyInt() {    return this.keyInt;  }   public void setKeyInt(Integer keyInt) {    this.keyInt = keyInt;  }   public String toString() {    return new ToStringBuilder(this)      .append("keyDate", getKeyDate())      .append("keyString", getKeyString())      .append("keyInt", getKeyInt())      .toString();  }   public boolean equals(Object other) {    if ( !(other instanceof TestTablePK) ) return false;    TestTablePK castOther = (TestTablePK) other;    return new EqualsBuilder()      .append(this.getKeyDate(), castOther.getKeyDate())      .append(this.getKeyString(), castOther.getKeyString())      .append(this.getKeyInt(), castOther.getKeyInt())      .isEquals();  }   public int hashCode() {    return new HashCodeBuilder()      .append(getKeyDate())      .append(getKeyString())      .append(getKeyInt())      .toHashCode();  }}TestHibernateSP.java:package con.lalfa.hibernate.test; import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import con.lalfa.hibernate.hibernate.HibernateSessionFactory;public class TestHibernateSP {   /**   * @param args   */  public static void main(String[] args) {    Session session = HibernateSessionFactory.currentSession();    Query query = session.getNamedQuery("selectAllValues_SP");    List list = query.list();    System.out.println(list);  } }


阅读全文(2585) | 回复(1) | 编辑 | 精华
 


回复:Hibernate 调用带有复合主键的stored procedure
软件技术,  电脑与网络

老泥(游客)发表评论于2007/5/28 10:47:49

存储过程的代码能不能写出来?


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144753288 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号