Hibernate 映射视图的联合主键

V4cDiseasesprevention
  1. package com.SAFAS.mobilecatch.server.hibernate.model;   
  2.   
  3. /**  
  4.  * V4cDiseasesprevention entity.  
  5.  *   
  6.  * @author MyEclipse Persistence Tools  
  7.  */  
  8.   
  9. public class V4cDiseasesprevention implements java.io.Serializable {   
  10.   
  11.     // Fields   
  12.   
  13.     private V4cDiseasespreventionId id;   
  14.   
  15.     // Constructors   
  16.   
  17.     /** default constructor */  
  18.     public V4cDiseasesprevention() {   
  19.     }   
  20.   
  21.     /** full constructor */  
  22.     public V4cDiseasesprevention(V4cDiseasespreventionId id) {   
  23.         this.id = id;   
  24.     }   
  25.   
  26.     // Property accessors   
  27.   
  28.     public V4cDiseasespreventionId getId() {   
  29.         return this.id;   
  30.     }   
  31.   
  32.     public void setId(V4cDiseasespreventionId id) {   
  33.         this.id = id;   
  34.     }   
  35.   
  36. }  



V4cDiseasespreventionId

  1. package com.SAFAS.mobilecatch.server.hibernate.model;   
  2.   
  3. /**  
  4.  * V4cDiseasespreventionId entity.  
  5.  *   
  6.  * @author MyEclipse Persistence Tools  
  7.  */  
  8.   
  9. public class V4cDiseasespreventionId implements java.io.Serializable {   
  10.   
  11.     // Fields   
  12.   
  13.     private Integer produceClassify4id;   
  14.     private String produceClassify4name;   
  15.     private Short qualityStandardId;   
  16.     private Short environmentStandardId;   
  17.     private Short producingRuleId;   
  18.     private Short produceSampleStandardId;   
  19.     private String producingRuleCode;   
  20.     private String producingRuleName;   
  21.     private String remark;   
  22.     private String pesticideName;   
  23.     private String preventionMethod;   
  24.   
  25.     // Constructors   
  26.   
  27.     /** default constructor */  
  28.     public V4cDiseasespreventionId() {   
  29.     }   
  30.   
  31.     /** minimal constructor */  
  32.     public V4cDiseasespreventionId(Integer produceClassify4id) {   
  33.         this.produceClassify4id = produceClassify4id;   
  34.     }   
  35.   
  36.     /** full constructor */  
  37.     public V4cDiseasespreventionId(Integer produceClassify4id,   
  38.             String produceClassify4name, Short qualityStandardId,   
  39.             Short environmentStandardId, Short producingRuleId,   
  40.             Short produceSampleStandardId, String producingRuleCode,   
  41.             String producingRuleName, String remark, String pesticideName,   
  42.             String preventionMethod) {   
  43.         this.produceClassify4id = produceClassify4id;   
  44.         this.produceClassify4name = produceClassify4name;   
  45.         this.qualityStandardId = qualityStandardId;   
  46.         this.environmentStandardId = environmentStandardId;   
  47.         this.producingRuleId = producingRuleId;   
  48.         this.produceSampleStandardId = produceSampleStandardId;   
  49.         this.producingRuleCode = producingRuleCode;   
  50.         this.producingRuleName = producingRuleName;   
  51.         this.remark = remark;   
  52.         this.pesticideName = pesticideName;   
  53.         this.preventionMethod = preventionMethod;   
  54.     }   
  55.   
  56.     // Property accessors   
  57.   
  58.     public Integer getProduceClassify4id() {   
  59.         return this.produceClassify4id;   
  60.     }   
  61.   
  62.     public void setProduceClassify4id(Integer produceClassify4id) {   
  63.         this.produceClassify4id = produceClassify4id;   
  64.     }   
  65.   
  66.     public String getProduceClassify4name() {   
  67.         return this.produceClassify4name;   
  68.     }   
  69.   
  70.     public void setProduceClassify4name(String produceClassify4name) {   
  71.         this.produceClassify4name = produceClassify4name;   
  72.     }   
  73.   
  74.     public Short getQualityStandardId() {   
  75.         return this.qualityStandardId;   
  76.     }   
  77.   
  78.     public void setQualityStandardId(Short qualityStandardId) {   
  79.         this.qualityStandardId = qualityStandardId;   
  80.     }   
  81.   
  82.     public Short getEnvironmentStandardId() {   
  83.         return this.environmentStandardId;   
  84.     }   
  85.   
  86.     public void setEnvironmentStandardId(Short environmentStandardId) {   
  87.         this.environmentStandardId = environmentStandardId;   
  88.     }   
  89.   
  90.     public Short getProducingRuleId() {   
  91.         return this.producingRuleId;   
  92.     }   
  93.   
  94.     public void setProducingRuleId(Short producingRuleId) {   
  95.         this.producingRuleId = producingRuleId;   
  96.     }   
  97.   
  98.     public Short getProduceSampleStandardId() {   
  99.         return this.produceSampleStandardId;   
  100.     }   
  101.   
  102.     public void setProduceSampleStandardId(Short produceSampleStandardId) {   
  103.         this.produceSampleStandardId = produceSampleStandardId;   
  104.     }   
  105.   
  106.     public String getProducingRuleCode() {   
  107.         return this.producingRuleCode;   
  108.     }   
  109.   
  110.     public void setProducingRuleCode(String producingRuleCode) {   
  111.         this.producingRuleCode = producingRuleCode;   
  112.     }   
  113.   
  114.     public String getProducingRuleName() {   
  115.         return this.producingRuleName;   
  116.     }   
  117.   
  118.     public void setProducingRuleName(String producingRuleName) {   
  119.         this.producingRuleName = producingRuleName;   
  120.     }   
  121.   
  122.     public String getRemark() {   
  123.         return this.remark;   
  124.     }   
  125.   
  126.     public void setRemark(String remark) {   
  127.         this.remark = remark;   
  128.     }   
  129.   
  130.     public String getPesticideName() {   
  131.         return this.pesticideName;   
  132.     }   
  133.   
  134.     public void setPesticideName(String pesticideName) {   
  135.         this.pesticideName = pesticideName;   
  136.     }   
  137.   
  138.     public String getPreventionMethod() {   
  139.         return this.preventionMethod;   
  140.     }   
  141.   
  142.     public void setPreventionMethod(String preventionMethod) {   
  143.         this.preventionMethod = preventionMethod;   
  144.     }   
  145.   
  146.     public boolean equals(Object other) {   
  147.         if ((this == other))   
  148.             return true;   
  149.         if ((other == null))   
  150.             return false;   
  151.         if (!(other instanceof V4cDiseasespreventionId))   
  152.             return false;   
  153.         V4cDiseasespreventionId castOther = (V4cDiseasespreventionId) other;   
  154.   
  155.         return ((this.getProduceClassify4id() == castOther   
  156.                 .getProduceClassify4id()) || (this.getProduceClassify4id() != null  
  157.                 && castOther.getProduceClassify4id() != null && this  
  158.                 .getProduceClassify4id().equals(   
  159.                         castOther.getProduceClassify4id())))   
  160.                 && ((this.getProduceClassify4name() == castOther   
  161.                         .getProduceClassify4name()) || (this  
  162.                         .getProduceClassify4name() != null  
  163.                         && castOther.getProduceClassify4name() != null && this  
  164.                         .getProduceClassify4name().equals(   
  165.                                 castOther.getProduceClassify4name())))   
  166.                 && ((this.getQualityStandardId() == castOther   
  167.                         .getQualityStandardId()) || (this  
  168.                         .getQualityStandardId() != null  
  169.                         && castOther.getQualityStandardId() != null && this  
  170.                         .getQualityStandardId().equals(   
  171.                                 castOther.getQualityStandardId())))   
  172.                 && ((this.getEnvironmentStandardId() == castOther   
  173.                         .getEnvironmentStandardId()) || (this  
  174.                         .getEnvironmentStandardId() != null  
  175.                         && castOther.getEnvironmentStandardId() != null && this  
  176.                         .getEnvironmentStandardId().equals(   
  177.                                 castOther.getEnvironmentStandardId())))   
  178.                 && ((this.getProducingRuleId() == castOther   
  179.                         .getProducingRuleId()) || (this.getProducingRuleId() != null  
  180.                         && castOther.getProducingRuleId() != null && this  
  181.                         .getProducingRuleId().equals(   
  182.                                 castOther.getProducingRuleId())))   
  183.                 && ((this.getProduceSampleStandardId() == castOther   
  184.                         .getProduceSampleStandardId()) || (this  
  185.                         .getProduceSampleStandardId() != null  
  186.                         && castOther.getProduceSampleStandardId() != null && this  
  187.                         .getProduceSampleStandardId().equals(   
  188.                                 castOther.getProduceSampleStandardId())))   
  189.                 && ((this.getProducingRuleCode() == castOther   
  190.                         .getProducingRuleCode()) || (this  
  191.                         .getProducingRuleCode() != null  
  192.                         && castOther.getProducingRuleCode() != null && this  
  193.                         .getProducingRuleCode().equals(   
  194.                                 castOther.getProducingRuleCode())))   
  195.                 && ((this.getProducingRuleName() == castOther   
  196.                         .getProducingRuleName()) || (this  
  197.                         .getProducingRuleName() != null  
  198.                         && castOther.getProducingRuleName() != null && this  
  199.                         .getProducingRuleName().equals(   
  200.                                 castOther.getProducingRuleName())))   
  201.                 && ((this.getRemark() == castOther.getRemark()) || (this  
  202.                         .getRemark() != null  
  203.                         && castOther.getRemark() != null && this.getRemark()   
  204.                         .equals(castOther.getRemark())))   
  205.                 && ((this.getPesticideName() == castOther.getPesticideName()) || (this  
  206.                         .getPesticideName() != null  
  207.                         && castOther.getPesticideName() != null && this  
  208.                         .getPesticideName()   
  209.                         .equals(castOther.getPesticideName())))   
  210.                 && ((this.getPreventionMethod() == castOther   
  211.                         .getPreventionMethod()) || (this.getPreventionMethod() != null  
  212.                         && castOther.getPreventionMethod() != null && this  
  213.                         .getPreventionMethod().equals(   
  214.                                 castOther.getPreventionMethod())));   
  215.     }   
  216.   
  217.     public int hashCode() {   
  218.         int result = 17;   
  219.   
  220.         result = 37  
  221.                 * result   
  222.                 + (getProduceClassify4id() == null ? 0 : this  
  223.                         .getProduceClassify4id().hashCode());   
  224.         result = 37  
  225.                 * result   
  226.                 + (getProduceClassify4name() == null ? 0 : this  
  227.                         .getProduceClassify4name().hashCode());   
  228.         result = 37  
  229.                 * result   
  230.                 + (getQualityStandardId() == null ? 0 : this  
  231.                         .getQualityStandardId().hashCode());   
  232.         result = 37  
  233.                 * result   
  234.                 + (getEnvironmentStandardId() == null ? 0 : this  
  235.                         .getEnvironmentStandardId().hashCode());   
  236.         result = 37  
  237.                 * result   
  238.                 + (getProducingRuleId() == null ? 0 : this.getProducingRuleId()   
  239.                         .hashCode());   
  240.         result = 37  
  241.                 * result   
  242.                 + (getProduceSampleStandardId() == null ? 0 : this  
  243.                         .getProduceSampleStandardId().hashCode());   
  244.         result = 37  
  245.                 * result   
  246.                 + (getProducingRuleCode() == null ? 0 : this  
  247.                         .getProducingRuleCode().hashCode());   
  248.         result = 37  
  249.                 * result   
  250.                 + (getProducingRuleName() == null ? 0 : this  
  251.                         .getProducingRuleName().hashCode());   
  252.         result = 37 * result   
  253.                 + (getRemark() == null ? 0 : this.getRemark().hashCode());   
  254.         result = 37  
  255.                 * result   
  256.                 + (getPesticideName() == null ? 0 : this.getPesticideName()   
  257.                         .hashCode());   
  258.         result = 37  
  259.                 * result   
  260.                 + (getPreventionMethod() == null ? 0 : this  
  261.                         .getPreventionMethod().hashCode());   
  262.         return result;   
  263.     }   
  264.   
  265. }  

映射文件:

V4cDiseasesprevention.hbm.xml

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"   
  3. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
  4. <!--   
  5.     Mapping file autogenerated by MyEclipse Persistence Tools  
  6. -->  
  7. <hibernate-mapping>  
  8.     <class name="com.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasesprevention" table="v_4c_diseasesprevention" catalog="safas">  
  9.         <composite-id name="id" class="com.pickedpoint.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasespreventionId">  
  10.             <key-property name="produceClassify4id" type="java.lang.Integer">  
  11.                 <column name="produceClassify_4ID" />  
  12.             </key-property>  
  13.             <key-property name="produceClassify4name" type="java.lang.String">  
  14.                 <column name="produceClassify_4Name" length="20" />  
  15.             </key-property>  
  16.             <key-property name="qualityStandardId" type="java.lang.Short">  
  17.                 <column name="qualityStandardID" />  
  18.             </key-property>  
  19.             <key-property name="environmentStandardId" type="java.lang.Short">  
  20.                 <column name="environmentStandardID" />  
  21.             </key-property>  
  22.             <key-property name="producingRuleId" type="java.lang.Short">  
  23.                 <column name="producingRuleID" />  
  24.             </key-property>  
  25.             <key-property name="produceSampleStandardId" type="java.lang.Short">  
  26.                 <column name="produceSampleStandardID" />  
  27.             </key-property>  
  28.             <key-property name="producingRuleCode" type="java.lang.String">  
  29.                 <column name="producingRuleCode" />  
  30.             </key-property>  
  31.             <key-property name="producingRuleName" type="java.lang.String">  
  32.                 <column name="producingRuleName" length="50" />  
  33.             </key-property>  
  34.             <key-property name="remark" type="java.lang.String">  
  35.                 <column name="remark" />  
  36.             </key-property>  
  37.             <key-property name="pesticideName" type="java.lang.String">  
  38.                 <column name="pesticideName" length="50" />  
  39.             </key-property>  
  40.             <key-property name="preventionMethod" type="java.lang.String">  
  41.                 <column name="preventionMethod" />  
  42.             </key-property>  
  43.         </composite-id>  
  44.     </class>  
  45. </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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值