分享
 
 
 

Hibernate 调用带有复合主键的stored procedure

王朝java/jsp·作者佚名  2006-03-30
窄屏简体版  字體: |||超大  

Hibernate 调用带有复合主键的stored procedure

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="com.bgi.fia.hibernate.TestTable"

table="TestTable"

>

<meta attribute="class-description" inherit="false">

@hibernate.class

table="TestTable"

</meta>

<composite-id name="comp_id" class="com.bgi.fia.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="com.bgi.fia.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.java

package com.bgi.fia.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 com.bgi.fia.hibernate.TestTablePK comp_id;

/** nullable persistent field */

private String conteng;

/** full constructor */

public TestTable(com.bgi.fia.hibernate.TestTablePK comp_id, String conteng) {

this.comp_id = comp_id;

this.conteng = conteng;

}

/** default constructor */

public TestTable() {

}

/** minimal constructor */

public TestTable(com.bgi.fia.hibernate.TestTablePK comp_id) {

this.comp_id = comp_id;

}

/**

* @hibernate.id

* generator-class="assigned"

*

*/

public com.bgi.fia.hibernate.TestTablePK getComp_id() {

return this.comp_id;

}

public void setComp_id(com.bgi.fia.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 com.bgi.fia.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 com.bgi.fia.test;

import java.util.List;

import org.hibernate.Query;

import org.hibernate.Session;

import com.bgi.fia.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);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有