您的位置:首页 > 其它

Hibernate 映射视图的联合主键

2008-09-28 17:48 344 查看
V4cDiseasesprevention

package com.SAFAS.mobilecatch.server.hibernate.model;

/**

* V4cDiseasesprevention entity.

*

* @author MyEclipse Persistence Tools

*/

public class V4cDiseasesprevention implements java.io.Serializable {

// Fields

private V4cDiseasespreventionId id;

// Constructors

/** default constructor */

public V4cDiseasesprevention() {

}

/** full constructor */

public V4cDiseasesprevention(V4cDiseasespreventionId id) {

this.id = id;

}

// Property accessors

public V4cDiseasespreventionId getId() {

return this.id;

}

public void setId(V4cDiseasespreventionId id) {

this.id = id;

}

}

V4cDiseasespreventionId

package com.SAFAS.mobilecatch.server.hibernate.model;

/**

* V4cDiseasespreventionId entity.

*

* @author MyEclipse Persistence Tools

*/

public class V4cDiseasespreventionId implements java.io.Serializable {

// Fields

private Integer produceClassify4id;

private String produceClassify4name;

private Short qualityStandardId;

private Short environmentStandardId;

private Short producingRuleId;

private Short produceSampleStandardId;

private String producingRuleCode;

private String producingRuleName;

private String remark;

private String pesticideName;

private String preventionMethod;

// Constructors

/** default constructor */

public V4cDiseasespreventionId() {

}

/** minimal constructor */

public V4cDiseasespreventionId(Integer produceClassify4id) {

this.produceClassify4id = produceClassify4id;

}

/** full constructor */

public V4cDiseasespreventionId(Integer produceClassify4id,

String produceClassify4name, Short qualityStandardId,

Short environmentStandardId, Short producingRuleId,

Short produceSampleStandardId, String producingRuleCode,

String producingRuleName, String remark, String pesticideName,

String preventionMethod) {

this.produceClassify4id = produceClassify4id;

this.produceClassify4name = produceClassify4name;

this.qualityStandardId = qualityStandardId;

this.environmentStandardId = environmentStandardId;

this.producingRuleId = producingRuleId;

this.produceSampleStandardId = produceSampleStandardId;

this.producingRuleCode = producingRuleCode;

this.producingRuleName = producingRuleName;

this.remark = remark;

this.pesticideName = pesticideName;

this.preventionMethod = preventionMethod;

}

// Property accessors

public Integer getProduceClassify4id() {

return this.produceClassify4id;

}

public void setProduceClassify4id(Integer produceClassify4id) {

this.produceClassify4id = produceClassify4id;

}

public String getProduceClassify4name() {

return this.produceClassify4name;

}

public void setProduceClassify4name(String produceClassify4name) {

this.produceClassify4name = produceClassify4name;

}

public Short getQualityStandardId() {

return this.qualityStandardId;

}

public void setQualityStandardId(Short qualityStandardId) {

this.qualityStandardId = qualityStandardId;

}

public Short getEnvironmentStandardId() {

return this.environmentStandardId;

}

public void setEnvironmentStandardId(Short environmentStandardId) {

this.environmentStandardId = environmentStandardId;

}

public Short getProducingRuleId() {

return this.producingRuleId;

}

public void setProducingRuleId(Short producingRuleId) {

this.producingRuleId = producingRuleId;

}

public Short getProduceSampleStandardId() {

return this.produceSampleStandardId;

}

public void setProduceSampleStandardId(Short produceSampleStandardId) {

this.produceSampleStandardId = produceSampleStandardId;

}

public String getProducingRuleCode() {

return this.producingRuleCode;

}

public void setProducingRuleCode(String producingRuleCode) {

this.producingRuleCode = producingRuleCode;

}

public String getProducingRuleName() {

return this.producingRuleName;

}

public void setProducingRuleName(String producingRuleName) {

this.producingRuleName = producingRuleName;

}

public String getRemark() {

return this.remark;

}

public void setRemark(String remark) {

this.remark = remark;

}

public String getPesticideName() {

return this.pesticideName;

}

public void setPesticideName(String pesticideName) {

this.pesticideName = pesticideName;

}

public String getPreventionMethod() {

return this.preventionMethod;

}

public void setPreventionMethod(String preventionMethod) {

this.preventionMethod = preventionMethod;

}

public boolean equals(Object other) {

if ((this == other))

return true;

if ((other == null))

return false;

if (!(other instanceof V4cDiseasespreventionId))

return false;

V4cDiseasespreventionId castOther = (V4cDiseasespreventionId) other;

return ((this.getProduceClassify4id() == castOther

.getProduceClassify4id()) || (this.getProduceClassify4id() != null

&& castOther.getProduceClassify4id() != null && this

.getProduceClassify4id().equals(

castOther.getProduceClassify4id())))

&& ((this.getProduceClassify4name() == castOther

.getProduceClassify4name()) || (this

.getProduceClassify4name() != null

&& castOther.getProduceClassify4name() != null && this

.getProduceClassify4name().equals(

castOther.getProduceClassify4name())))

&& ((this.getQualityStandardId() == castOther

.getQualityStandardId()) || (this

.getQualityStandardId() != null

&& castOther.getQualityStandardId() != null && this

.getQualityStandardId().equals(

castOther.getQualityStandardId())))

&& ((this.getEnvironmentStandardId() == castOther

.getEnvironmentStandardId()) || (this

.getEnvironmentStandardId() != null

&& castOther.getEnvironmentStandardId() != null && this

.getEnvironmentStandardId().equals(

castOther.getEnvironmentStandardId())))

&& ((this.getProducingRuleId() == castOther

.getProducingRuleId()) || (this.getProducingRuleId() != null

&& castOther.getProducingRuleId() != null && this

.getProducingRuleId().equals(

castOther.getProducingRuleId())))

&& ((this.getProduceSampleStandardId() == castOther

.getProduceSampleStandardId()) || (this

.getProduceSampleStandardId() != null

&& castOther.getProduceSampleStandardId() != null && this

.getProduceSampleStandardId().equals(

castOther.getProduceSampleStandardId())))

&& ((this.getProducingRuleCode() == castOther

.getProducingRuleCode()) || (this

.getProducingRuleCode() != null

&& castOther.getProducingRuleCode() != null && this

.getProducingRuleCode().equals(

castOther.getProducingRuleCode())))

&& ((this.getProducingRuleName() == castOther

.getProducingRuleName()) || (this

.getProducingRuleName() != null

&& castOther.getProducingRuleName() != null && this

.getProducingRuleName().equals(

castOther.getProducingRuleName())))

&& ((this.getRemark() == castOther.getRemark()) || (this

.getRemark() != null

&& castOther.getRemark() != null && this.getRemark()

.equals(castOther.getRemark())))

&& ((this.getPesticideName() == castOther.getPesticideName()) || (this

.getPesticideName() != null

&& castOther.getPesticideName() != null && this

.getPesticideName()

.equals(castOther.getPesticideName())))

&& ((this.getPreventionMethod() == castOther

.getPreventionMethod()) || (this.getPreventionMethod() != null

&& castOther.getPreventionMethod() != null && this

.getPreventionMethod().equals(

castOther.getPreventionMethod())));

}

public int hashCode() {

int result = 17;

result = 37

* result

+ (getProduceClassify4id() == null ? 0 : this

.getProduceClassify4id().hashCode());

result = 37

* result

+ (getProduceClassify4name() == null ? 0 : this

.getProduceClassify4name().hashCode());

result = 37

* result

+ (getQualityStandardId() == null ? 0 : this

.getQualityStandardId().hashCode());

result = 37

* result

+ (getEnvironmentStandardId() == null ? 0 : this

.getEnvironmentStandardId().hashCode());

result = 37

* result

+ (getProducingRuleId() == null ? 0 : this.getProducingRuleId()

.hashCode());

result = 37

* result

+ (getProduceSampleStandardId() == null ? 0 : this

.getProduceSampleStandardId().hashCode());

result = 37

* result

+ (getProducingRuleCode() == null ? 0 : this

.getProducingRuleCode().hashCode());

result = 37

* result

+ (getProducingRuleName() == null ? 0 : this

.getProducingRuleName().hashCode());

result = 37 * result

+ (getRemark() == null ? 0 : this.getRemark().hashCode());

result = 37

* result

+ (getPesticideName() == null ? 0 : this.getPesticideName()

.hashCode());

result = 37

* result

+ (getPreventionMethod() == null ? 0 : this

.getPreventionMethod().hashCode());

return result;

}

}

映射文件:

V4cDiseasesprevention.hbm.xml

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!--

Mapping file autogenerated by MyEclipse Persistence Tools

-->

<hibernate-mapping>

<class name="com.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasesprevention" table="v_4c_diseasesprevention" catalog="safas">

<composite-id name="id" class="com.pickedpoint.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasespreventionId">

<key-property name="produceClassify4id" type="java.lang.Integer">

<column name="produceClassify_4ID" />

</key-property>

<key-property name="produceClassify4name" type="java.lang.String">

<column name="produceClassify_4Name" length="20" />

</key-property>

<key-property name="qualityStandardId" type="java.lang.Short">

<column name="qualityStandardID" />

</key-property>

<key-property name="environmentStandardId" type="java.lang.Short">

<column name="environmentStandardID" />

</key-property>

<key-property name="producingRuleId" type="java.lang.Short">

<column name="producingRuleID" />

</key-property>

<key-property name="produceSampleStandardId" type="java.lang.Short">

<column name="produceSampleStandardID" />

</key-property>

<key-property name="producingRuleCode" type="java.lang.String">

<column name="producingRuleCode" />

</key-property>

<key-property name="producingRuleName" type="java.lang.String">

<column name="producingRuleName" length="50" />

</key-property>

<key-property name="remark" type="java.lang.String">

<column name="remark" />

</key-property>

<key-property name="pesticideName" type="java.lang.String">

<column name="pesticideName" length="50" />

</key-property>

<key-property name="preventionMethod" type="java.lang.String">

<column name="preventionMethod" />

</key-property>

</composite-id>

</class>

</hibernate-mapping>

hibernate 默认是联合主键,这样的话如果有一项内容为空,则整个结果就会返回会空.

解决方法:

1.删除V4cDiseasespreventionId.java;

2.将V4cDiseasesprevention.java的属性全部替换为V4cDiseasespreventionId.java的,以及它的get,set方法.

3.修改映射文件为:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasesprevention" table="v_4c_diseasesprevention" catalog="safas">
<id name="produceClassify4id" type="java.lang.Integer">
<column name="produceClassify_4ID" />
</id>
<property name="produceClassify4name" type="java.lang.String">
<column name="produceClassify_4Name" length="20" />
</property>
<property name="qualityStandardId" type="java.lang.Short">
<column name="qualityStandardID" />
</property>
<property name="environmentStandardId" type="java.lang.Short">
<column name="environmentStandardID" />
</property>
<property name="producingRuleId" type="java.lang.Short">
<column name="producingRuleID" />
</property>
<property name="produceSampleStandardId" type="java.lang.Short">
<column name="produceSampleStandardID" />
</property>
<property name="producingRuleCode" type="java.lang.String">
<column name="producingRuleCode" />
</property>
<property name="producingRuleName" type="java.lang.String">
<column name="producingRuleName" length="50" />
</property>
<property name="remark" type="java.lang.String">
<column name="remark" />
</property>
<property name="pesticideName" type="java.lang.String">
<column name="pesticideName" length="50" />
</property>
<property name="preventionMethod" type="java.lang.String">
<column name="preventionMethod" />
</property>
</class>
</hibernate-mapping>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: