Hibernate 映射视图的联合主键

V4cDiseasesprevention
  1. packagecom.SAFAS.mobilecatch.server.hibernate.model;
  2. /**
  3. *V4cDiseasespreventionentity.
  4. *
  5. *@authorMyEclipsePersistenceTools
  6. */
  7. publicclassV4cDiseasespreventionimplementsjava.io.Serializable{
  8. //Fields
  9. privateV4cDiseasespreventionIdid;
  10. //Constructors
  11. /**defaultconstructor*/
  12. publicV4cDiseasesprevention(){
  13. }
  14. /**fullconstructor*/
  15. publicV4cDiseasesprevention(V4cDiseasespreventionIdid){
  16. this.id=id;
  17. }
  18. //Propertyaccessors
  19. publicV4cDiseasespreventionIdgetId(){
  20. returnthis.id;
  21. }
  22. publicvoidsetId(V4cDiseasespreventionIdid){
  23. this.id=id;
  24. }
  25. }



V4cDiseasespreventionId

  1. packagecom.SAFAS.mobilecatch.server.hibernate.model;
  2. /**
  3. *V4cDiseasespreventionIdentity.
  4. *
  5. *@authorMyEclipsePersistenceTools
  6. */
  7. publicclassV4cDiseasespreventionIdimplementsjava.io.Serializable{
  8. //Fields
  9. privateIntegerproduceClassify4id;
  10. privateStringproduceClassify4name;
  11. privateShortqualityStandardId;
  12. privateShortenvironmentStandardId;
  13. privateShortproducingRuleId;
  14. privateShortproduceSampleStandardId;
  15. privateStringproducingRuleCode;
  16. privateStringproducingRuleName;
  17. privateStringremark;
  18. privateStringpesticideName;
  19. privateStringpreventionMethod;
  20. //Constructors
  21. /**defaultconstructor*/
  22. publicV4cDiseasespreventionId(){
  23. }
  24. /**minimalconstructor*/
  25. publicV4cDiseasespreventionId(IntegerproduceClassify4id){
  26. this.produceClassify4id=produceClassify4id;
  27. }
  28. /**fullconstructor*/
  29. publicV4cDiseasespreventionId(IntegerproduceClassify4id,
  30. StringproduceClassify4name,ShortqualityStandardId,
  31. ShortenvironmentStandardId,ShortproducingRuleId,
  32. ShortproduceSampleStandardId,StringproducingRuleCode,
  33. StringproducingRuleName,Stringremark,StringpesticideName,
  34. StringpreventionMethod){
  35. this.produceClassify4id=produceClassify4id;
  36. this.produceClassify4name=produceClassify4name;
  37. this.qualityStandardId=qualityStandardId;
  38. this.environmentStandardId=environmentStandardId;
  39. this.producingRuleId=producingRuleId;
  40. this.produceSampleStandardId=produceSampleStandardId;
  41. this.producingRuleCode=producingRuleCode;
  42. this.producingRuleName=producingRuleName;
  43. this.remark=remark;
  44. this.pesticideName=pesticideName;
  45. this.preventionMethod=preventionMethod;
  46. }
  47. //Propertyaccessors
  48. publicIntegergetProduceClassify4id(){
  49. returnthis.produceClassify4id;
  50. }
  51. publicvoidsetProduceClassify4id(IntegerproduceClassify4id){
  52. this.produceClassify4id=produceClassify4id;
  53. }
  54. publicStringgetProduceClassify4name(){
  55. returnthis.produceClassify4name;
  56. }
  57. publicvoidsetProduceClassify4name(StringproduceClassify4name){
  58. this.produceClassify4name=produceClassify4name;
  59. }
  60. publicShortgetQualityStandardId(){
  61. returnthis.qualityStandardId;
  62. }
  63. publicvoidsetQualityStandardId(ShortqualityStandardId){
  64. this.qualityStandardId=qualityStandardId;
  65. }
  66. publicShortgetEnvironmentStandardId(){
  67. returnthis.environmentStandardId;
  68. }
  69. publicvoidsetEnvironmentStandardId(ShortenvironmentStandardId){
  70. this.environmentStandardId=environmentStandardId;
  71. }
  72. publicShortgetProducingRuleId(){
  73. returnthis.producingRuleId;
  74. }
  75. publicvoidsetProducingRuleId(ShortproducingRuleId){
  76. this.producingRuleId=producingRuleId;
  77. }
  78. publicShortgetProduceSampleStandardId(){
  79. returnthis.produceSampleStandardId;
  80. }
  81. publicvoidsetProduceSampleStandardId(ShortproduceSampleStandardId){
  82. this.produceSampleStandardId=produceSampleStandardId;
  83. }
  84. publicStringgetProducingRuleCode(){
  85. returnthis.producingRuleCode;
  86. }
  87. publicvoidsetProducingRuleCode(StringproducingRuleCode){
  88. this.producingRuleCode=producingRuleCode;
  89. }
  90. publicStringgetProducingRuleName(){
  91. returnthis.producingRuleName;
  92. }
  93. publicvoidsetProducingRuleName(StringproducingRuleName){
  94. this.producingRuleName=producingRuleName;
  95. }
  96. publicStringgetRemark(){
  97. returnthis.remark;
  98. }
  99. publicvoidsetRemark(Stringremark){
  100. this.remark=remark;
  101. }
  102. publicStringgetPesticideName(){
  103. returnthis.pesticideName;
  104. }
  105. publicvoidsetPesticideName(StringpesticideName){
  106. this.pesticideName=pesticideName;
  107. }
  108. publicStringgetPreventionMethod(){
  109. returnthis.preventionMethod;
  110. }
  111. publicvoidsetPreventionMethod(StringpreventionMethod){
  112. this.preventionMethod=preventionMethod;
  113. }
  114. publicbooleanequals(Objectother){
  115. if((this==other))
  116. returntrue;
  117. if((other==null))
  118. returnfalse;
  119. if(!(otherinstanceofV4cDiseasespreventionId))
  120. returnfalse;
  121. V4cDiseasespreventionIdcastOther=(V4cDiseasespreventionId)other;
  122. return((this.getProduceClassify4id()==castOther
  123. .getProduceClassify4id())||(this.getProduceClassify4id()!=null
  124. &&castOther.getProduceClassify4id()!=null&&this
  125. .getProduceClassify4id().equals(
  126. castOther.getProduceClassify4id())))
  127. &&((this.getProduceClassify4name()==castOther
  128. .getProduceClassify4name())||(this
  129. .getProduceClassify4name()!=null
  130. &&castOther.getProduceClassify4name()!=null&&this
  131. .getProduceClassify4name().equals(
  132. castOther.getProduceClassify4name())))
  133. &&((this.getQualityStandardId()==castOther
  134. .getQualityStandardId())||(this
  135. .getQualityStandardId()!=null
  136. &&castOther.getQualityStandardId()!=null&&this
  137. .getQualityStandardId().equals(
  138. castOther.getQualityStandardId())))
  139. &&((this.getEnvironmentStandardId()==castOther
  140. .getEnvironmentStandardId())||(this
  141. .getEnvironmentStandardId()!=null
  142. &&castOther.getEnvironmentStandardId()!=null&&this
  143. .getEnvironmentStandardId().equals(
  144. castOther.getEnvironmentStandardId())))
  145. &&((this.getProducingRuleId()==castOther
  146. .getProducingRuleId())||(this.getProducingRuleId()!=null
  147. &&castOther.getProducingRuleId()!=null&&this
  148. .getProducingRuleId().equals(
  149. castOther.getProducingRuleId())))
  150. &&((this.getProduceSampleStandardId()==castOther
  151. .getProduceSampleStandardId())||(this
  152. .getProduceSampleStandardId()!=null
  153. &&castOther.getProduceSampleStandardId()!=null&&this
  154. .getProduceSampleStandardId().equals(
  155. castOther.getProduceSampleStandardId())))
  156. &&((this.getProducingRuleCode()==castOther
  157. .getProducingRuleCode())||(this
  158. .getProducingRuleCode()!=null
  159. &&castOther.getProducingRuleCode()!=null&&this
  160. .getProducingRuleCode().equals(
  161. castOther.getProducingRuleCode())))
  162. &&((this.getProducingRuleName()==castOther
  163. .getProducingRuleName())||(this
  164. .getProducingRuleName()!=null
  165. &&castOther.getProducingRuleName()!=null&&this
  166. .getProducingRuleName().equals(
  167. castOther.getProducingRuleName())))
  168. &&((this.getRemark()==castOther.getRemark())||(this
  169. .getRemark()!=null
  170. &&castOther.getRemark()!=null&&this.getRemark()
  171. .equals(castOther.getRemark())))
  172. &&((this.getPesticideName()==castOther.getPesticideName())||(this
  173. .getPesticideName()!=null
  174. &&castOther.getPesticideName()!=null&&this
  175. .getPesticideName()
  176. .equals(castOther.getPesticideName())))
  177. &&((this.getPreventionMethod()==castOther
  178. .getPreventionMethod())||(this.getPreventionMethod()!=null
  179. &&castOther.getPreventionMethod()!=null&&this
  180. .getPreventionMethod().equals(
  181. castOther.getPreventionMethod())));
  182. }
  183. publicinthashCode(){
  184. intresult=17;
  185. result=37
  186. *result
  187. +(getProduceClassify4id()==null?0:this
  188. .getProduceClassify4id().hashCode());
  189. result=37
  190. *result
  191. +(getProduceClassify4name()==null?0:this
  192. .getProduceClassify4name().hashCode());
  193. result=37
  194. *result
  195. +(getQualityStandardId()==null?0:this
  196. .getQualityStandardId().hashCode());
  197. result=37
  198. *result
  199. +(getEnvironmentStandardId()==null?0:this
  200. .getEnvironmentStandardId().hashCode());
  201. result=37
  202. *result
  203. +(getProducingRuleId()==null?0:this.getProducingRuleId()
  204. .hashCode());
  205. result=37
  206. *result
  207. +(getProduceSampleStandardId()==null?0:this
  208. .getProduceSampleStandardId().hashCode());
  209. result=37
  210. *result
  211. +(getProducingRuleCode()==null?0:this
  212. .getProducingRuleCode().hashCode());
  213. result=37
  214. *result
  215. +(getProducingRuleName()==null?0:this
  216. .getProducingRuleName().hashCode());
  217. result=37*result
  218. +(getRemark()==null?0:this.getRemark().hashCode());
  219. result=37
  220. *result
  221. +(getPesticideName()==null?0:this.getPesticideName()
  222. .hashCode());
  223. result=37
  224. *result
  225. +(getPreventionMethod()==null?0:this
  226. .getPreventionMethod().hashCode());
  227. returnresult;
  228. }
  229. }

映射文件:

V4cDiseasesprevention.hbm.xml

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN"
  3. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  4. <!--
  5. MappingfileautogeneratedbyMyEclipsePersistenceTools
  6. -->
  7. <hibernate-mapping>
  8. <classname="com.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasesprevention"table="v_4c_diseasesprevention"catalog="safas">
  9. <composite-idname="id"class="com.pickedpoint.SAFAS.mobilecatch.server.hibernate.model.V4cDiseasespreventionId">
  10. <key-propertyname="produceClassify4id"type="java.lang.Integer">
  11. <columnname="produceClassify_4ID"/>
  12. </key-property>
  13. <key-propertyname="produceClassify4name"type="java.lang.String">
  14. <columnname="produceClassify_4Name"length="20"/>
  15. </key-property>
  16. <key-propertyname="qualityStandardId"type="java.lang.Short">
  17. <columnname="qualityStandardID"/>
  18. </key-property>
  19. <key-propertyname="environmentStandardId"type="java.lang.Short">
  20. <columnname="environmentStandardID"/>
  21. </key-property>
  22. <key-propertyname="producingRuleId"type="java.lang.Short">
  23. <columnname="producingRuleID"/>
  24. </key-property>
  25. <key-propertyname="produceSampleStandardId"type="java.lang.Short">
  26. <columnname="produceSampleStandardID"/>
  27. </key-property>
  28. <key-propertyname="producingRuleCode"type="java.lang.String">
  29. <columnname="producingRuleCode"/>
  30. </key-property>
  31. <key-propertyname="producingRuleName"type="java.lang.String">
  32. <columnname="producingRuleName"length="50"/>
  33. </key-property>
  34. <key-propertyname="remark"type="java.lang.String">
  35. <columnname="remark"/>
  36. </key-property>
  37. <key-propertyname="pesticideName"type="java.lang.String">
  38. <columnname="pesticideName"length="50"/>
  39. </key-property>
  40. <key-propertyname="preventionMethod"type="java.lang.String">
  41. <columnname="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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值