JPA Federated primary key @ EmbeddedId detailed instructions with query examples

Source: Internet
Author: User
It took two hours to solve the problem. There was too little information on the internet. Record the details and view the source file TBicPrmCompute and TBicPrmComputePK.
Package com. isoftstone. core. domain; import java. io. serializable; import javax. persistence. *;/*** The persistent class for the T_BIC_PRM_COMPUTE database table. **/@ Entity @ NamedQueries ({@ NamedQuery (name = "findPrmComputeById", query = "select d from TBicPrmCompute d where d. id. CBisCode =? 1 and d. id. CBicNo =? 2 and d. id. CProdNo =? 3 ")}) @ Table (name =" T_BIC_PRM_COMPUTE ") public class TBicPrmCompute implements Serializable {private static final long serialVersionUID = 1L; private region id; private String cBsnsTyp; private String cCmpnyAgtCde; private String cSlsCde; private String cYl1; private String cYl2; private Double nMaxInsrntTm; private Double nMinInsrntTm; private Double nRate; private Double nTotalAmt; public TBicPrmCompute () {}@ EmbeddedId public TBicPrmComputePK getId () {return this. id;} public void setId (TBicPrmComputePK id) {this. id = id ;}@ Column (name = "C_BSNS_TYP") public String getCBsnsTyp () {return this. cBsnsTyp;} public void setCBsnsTyp (String cBsnsTyp) {this. cBsnsTyp = cBsnsTyp;} @ Column (name = "C_CMPNY_AGT_CDE") public String getCCmpnyAgtCde () {return this. cCmpnyAgtCde;} public void setCCmpnyAgtCde (String cCmpnyAgtCde) {this. cCmpnyAgtCde = cCmpnyAgtCde;} @ Column (name = "C_SLS_CDE") public String getCSlsCde () {return this. cSlsCde;} public void setCSlsCde (String cSlsCde) {this. cSlsCde = cSlsCde;} @ Column (name = "C_YL1") public String getCYl1 () {return this. cYl1;} public void setCYl1 (String cYl1) {this. cYl1 = cYl1 ;}@ Column (name = "C_YL2") public String getCYl2 () {return this. cYl2;} public void setCYl2 (String cYl2) {this. cYl2 = cYl2;} @ Column (name = "N_MAX_INSRNT_TM") public Double getNMaxInsrntTm () {return this. nMaxInsrntTm;} public void setNMaxInsrntTm (Double nMaxInsrntTm) {this. nMaxInsrntTm = nMaxInsrntTm;} @ Column (name = "N_MIN_INSRNT_TM") public Double getNMinInsrntTm () {return this. nMinInsrntTm;} public void setNMinInsrntTm (Double nMinInsrntTm) {this. nMinInsrntTm = nMinInsrntTm;} @ Column (name = "N_RATE") public Double getNRate () {return this. nRate;} public void setNRate (Double nRate) {this. nRate = nRate;} @ Column (name = "N_TOTAL_AMT") public Double getNTotalAmt () {return this. nTotalAmt;} public void setNTotalAmt (Double nTotalAmt) {this. nTotalAmt = nTotalAmt ;}}
Package com. isoftstone. core. domain; import java. io. serializable; import javax. persistence. *;/*** The primary key class for the T_BIC_PRM_COMPUTE database table. **/@ Embeddablepublic class TBicPrmComputePK implements Serializable {// default serial version id, required for serializable classes. private static final long serialVersionUID = 1L; private String cProdNo; private String cBisCode; private String cBicNo; public TBicPrmComputePK () {}@ Column (name = "C_PROD_NO") public String getCProdNo () {return this. cProdNo;} public void setCProdNo (String cProdNo) {this. cProdNo = cProdNo;} @ Column (name = "C_BIS_CODE") public String getCBisCode () {return this. cBisCode;} public void setCBisCode (String cBisCode) {this. cBisCode = cBisCode;} @ Column (name = "C_BIC_NO") public String getCBicNo () {retur N this. cBicNo;} public void setCBicNo (String cBicNo) {this. cBicNo = cBicNo;} public boolean equals (Object other) {if (this = other) {return true;} if (! (Other instanceof TBicPrmComputePK) {return false;} TBicPrmComputePK castOther = (TBicPrmComputePK) other; return this. cProdNo. equals (castOther. cProdNo) & this. cBisCode. equals (castOther. cBisCode) & this. cBicNo. equals (castOther. cBicNo);} public int hashCode () {final int prime = 31; int hash = 17; hash = hash * prime + this. cProdNo. hashCode (); hash = hash * prime + this. cBisCode. hashCode (); hash = hash * prime + this. cBicNo. hashCode (); return hash ;}}

 

The key is that it takes a long time to query the JPQL syntax @ NamedQueries ({
@ NamedQuery (name = "findPrmComputeById", query = "select d from TBicPrmCompute d where d. id. CBisCode =? 1 and d. id. CBicNo =? 2 and d. id. CProdNo =? 3 ")
}) DAOImpl implementation class @ Transactional
@ Override
Public TBicPrmCompute findPrmComputeById (String cBisCode, String cBicNo, String cProdNo)
Throws DataAccessException {
Query query = createNamedQuery ("findPrmComputeById",-1,-1, cBisCode, cBicNo, cProdNo );
Return (TBicPrmCompute) query. getSingleResult ();
} Call the interface TBicPrmCompute tBicPrmCompute = prmComputeDAO. findPrmComputeById (cBisCode, cBicNo, cProdNo). Note that @ EmbeddedId
Public TBicPrmComputePK getId (){
Return this. id;
} Generally, the attribute for writing JPQL is from EntityA d where d. propertyGetName, but because the Federated primary key object needs to be used as the JPQL condition, let's look at the preceding Federated primary key ID. For example, if you want to use the attribute of ID as the condition, write it as d. id. A =? 1. This is not the name of the get method. It is directly the name of the attribute and then the name of the get method getA ().

JPA Federated primary key @ EmbeddedId detailed instructions with query examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.