Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate hql insert a record into table with composite key
    primarykey
    data
    text
    <p>I want to insert a data into a table which contains a composite key.</p> <p>I work with hibernate HQL.</p> <p>I generate a hbm and Java class and I develop a function in order to insert a new record into a table</p> <p>The arrived to insert a new record but in the same time an exception will be generate</p> <p>this is UseCases.hbm</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt; &lt;!-- Generated 7 ao?t 2013 15:46:08 by Hibernate Tools 3.4.0.CR1 --&gt; &lt;hibernate-mapping&gt; &lt;class name="com.dq.hibernate.model.UseCases" table="USE_CASES"&gt; &lt;composite-id name="id" class="com.dq.hibernate.model.UseCasesId"&gt; &lt;key-property name="upaId" type="string"&gt; &lt;column name="UPA_ID" length="15" /&gt; &lt;/key-property&gt; &lt;key-property name="lndcasesId" type="string"&gt; &lt;column name="LNDCASES_ID" length="40" /&gt; &lt;/key-property&gt; &lt;key-property name="parcelNo" type="string"&gt; &lt;column name="PARCEL_NO" length="20" /&gt; &lt;/key-property&gt; &lt;key-property name="parcelBlk" type="string"&gt; &lt;column name="PARCEL_BLK" length="3" /&gt; &lt;/key-property&gt; &lt;key-property name="parcelGrp" type="string"&gt; &lt;column name="PARCEL_GRP" length="5" /&gt; &lt;/key-property&gt; &lt;/composite-id&gt; &lt;many-to-one name="urbanPlan" class="com.dq.hibernate.model.UrbanPlan" update="false" insert="false" fetch="select"&gt; &lt;column name="UPA_ID" length="15"/&gt; &lt;/many-to-one&gt; &lt;many-to-one name="parcel" class="com.dq.hibernate.model.Parcel" update="false" insert="false" fetch="select"&gt; &lt;column name="PARCEL_NO" length="20" /&gt; &lt;column name="PARCEL_BLK" length="3" /&gt; &lt;column name="PARCEL_GRP" length="5" /&gt; &lt;/many-to-one&gt; &lt;many-to-one name="landCases" class="com.dq.hibernate.model.LandCases" update="false" insert="false" fetch="select"&gt; &lt;column name="LNDCASES_ID" length="40" not-null="true"/&gt; &lt;/many-to-one&gt; &lt;property name="ucaseOrderno" type="string"&gt; &lt;column name="UCASE_ORDERNO" length="20" /&gt; &lt;/property&gt; &lt;property name="ucaseIssuedate" type="date"&gt; &lt;column name="UCASE_ISSUEDATE" length="7"/&gt; &lt;/property&gt; &lt;property name="ucaseDocno" type="string"&gt; &lt;column name="UCASE_DOCNO" length="20" /&gt; &lt;/property&gt; &lt;property name="ucaseDesc" type="string"&gt; &lt;column name="UCASE_DESC" length="500" /&gt; &lt;/property&gt; &lt;property name="ucasedatesys" type="date"&gt; &lt;column name="UCASEDATESYS" length="7" /&gt; &lt;/property&gt; &lt;property name="ucaseIssuedatehj" type="string"&gt; &lt;column name="UCASE_ISSUEDATEHJ" length="10" /&gt; &lt;/property&gt; &lt;property name="ucaseNote" type="string"&gt; &lt;column name="UCASE_NOTE" length="500" /&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>and this is UseCases.java</p> <pre><code>package com.dq.hibernate.model; // Generated 7 ao&amp;#65533;t 2013 15:46:08 by Hibernate Tools 3.4.0.CR1 import java.util.Date; /** * UseCases generated by hbm2java */ public class UseCases implements java.io.Serializable { private UseCasesId id; private UrbanPlan urbanPlan; private Parcel parcel; private LandCases landCases; private String ucaseOrderno; private Date ucaseIssuedate; private String ucaseDocno; private String ucaseDesc; private Date ucasedatesys; private String ucaseIssuedatehj; private String ucaseNote; public UseCases() { } public UseCases(UrbanPlan urbanPlan, Parcel parcel, LandCases landCases, String ucaseOrderno, Date ucaseIssuedate) { this.urbanPlan = urbanPlan; this.parcel = parcel; this.landCases = landCases; this.ucaseOrderno = ucaseOrderno; this.ucaseIssuedate = ucaseIssuedate; } public UseCases(UseCasesId id) { super(); this.id = id; } public UseCases(UrbanPlan urbanPlan, Parcel parcel, LandCases landCases, String ucaseOrderno, Date ucaseIssuedate, String ucaseDocno, String ucaseDesc, Date ucasedatesys, String ucaseIssuedatehj, String ucaseNote) { super(); this.urbanPlan = urbanPlan; this.parcel = parcel; this.landCases = landCases; this.ucaseOrderno = ucaseOrderno; this.ucaseIssuedate = ucaseIssuedate; this.ucaseDocno = ucaseDocno; this.ucaseDesc = ucaseDesc; this.ucasedatesys = ucasedatesys; this.ucaseIssuedatehj = ucaseIssuedatehj; this.ucaseNote = ucaseNote; } public UrbanPlan getUrbanPlan() { return this.urbanPlan; } public void setUrbanPlan(UrbanPlan urbanPlan) { this.urbanPlan = urbanPlan; } public Parcel getParcel() { return this.parcel; } public void setParcel(Parcel parcel) { this.parcel = parcel; } public LandCases getLandCases() { return this.landCases; } public void setLandCases(LandCases landCases) { this.landCases = landCases; } public String getUcaseOrderno() { return this.ucaseOrderno; } public void setUcaseOrderno(String ucaseOrderno) { this.ucaseOrderno = ucaseOrderno; } public Date getUcaseIssuedate() { return this.ucaseIssuedate; } public void setUcaseIssuedate(Date ucaseIssuedate) { this.ucaseIssuedate = ucaseIssuedate; } public String getUcaseDocno() { return this.ucaseDocno; } public void setUcaseDocno(String ucaseDocno) { this.ucaseDocno = ucaseDocno; } public String getUcaseDesc() { return this.ucaseDesc; } public void setUcaseDesc(String ucaseDesc) { this.ucaseDesc = ucaseDesc; } public Date getUcasedatesys() { return this.ucasedatesys; } public void setUcasedatesys(Date ucasedatesys) { this.ucasedatesys = ucasedatesys; } public String getUcaseIssuedatehj() { return this.ucaseIssuedatehj; } public void setUcaseIssuedatehj(String ucaseIssuedatehj) { this.ucaseIssuedatehj = ucaseIssuedatehj; } public String getUcaseNote() { return ucaseNote; } public void setUcaseNote(String ucaseNote) { this.ucaseNote = ucaseNote; } public UseCasesId getId() { return id; } public void setId(UseCasesId id) { this.id = id; } } </code></pre> <p>UseCasesId.java: </p> <pre><code>package com.dq.hibernate.model; // Generated 7 ao&amp;#65533;t 2013 15:46:08 by Hibernate Tools 3.4.0.CR1 /** * UseCasesId generated by hbm2java */ public class UseCasesId implements java.io.Serializable { private String upaId; private String lndcasesId; private String parcelNo; private String parcelBlk; private String parcelGrp; public UseCasesId() { } public UseCasesId(String upaId, String lndcasesId, String parcelNo, String parcelBlk, String parcelGrp) { this.upaId = upaId; this.lndcasesId = lndcasesId; this.parcelNo = parcelNo; this.parcelBlk = parcelBlk; this.parcelGrp = parcelGrp; } public String getupaId() { return this.upaId; } public void setupaId(String upaId) { this.upaId = upaId; } public String getLndcasesId() { return this.lndcasesId; } public void setLndcasesId(String lndcasesId) { this.lndcasesId = lndcasesId; } public String getParcelNo() { return this.parcelNo; } public void setParcelNo(String parcelNo) { this.parcelNo = parcelNo; } public String getParcelBlk() { return this.parcelBlk; } public void setParcelBlk(String parcelBlk) { this.parcelBlk = parcelBlk; } public String getParcelGrp() { return this.parcelGrp; } public void setParcelGrp(String parcelGrp) { this.parcelGrp = parcelGrp; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof UseCasesId)) return false; UseCasesId castOther = (UseCasesId) other; return ((this.getupaId() == castOther.getupaId()) || (this .getupaId() != null &amp;&amp; castOther.getupaId() != null &amp;&amp; this .getupaId().equals(castOther.getupaId()))) &amp;&amp; ((this.getLndcasesId() == castOther.getLndcasesId()) || (this .getLndcasesId() != null &amp;&amp; castOther.getLndcasesId() != null &amp;&amp; this .getLndcasesId().equals(castOther.getLndcasesId()))) &amp;&amp; ((this.getParcelNo() == castOther.getParcelNo()) || (this .getParcelNo() != null &amp;&amp; castOther.getParcelNo() != null &amp;&amp; this .getParcelNo().equals(castOther.getParcelNo()))) &amp;&amp; ((this.getParcelBlk() == castOther.getParcelBlk()) || (this .getParcelBlk() != null &amp;&amp; castOther.getParcelBlk() != null &amp;&amp; this .getParcelBlk().equals(castOther.getParcelBlk()))) &amp;&amp; ((this.getParcelGrp() == castOther.getParcelGrp()) || (this .getParcelGrp() != null &amp;&amp; castOther.getParcelGrp() != null &amp;&amp; this .getParcelGrp().equals(castOther.getParcelGrp()))); } public int hashCode() { int result = 17; result = 37 * result + (getupaId() == null ? 0 : this.getupaId() .hashCode()); result = 37 * result + (getLndcasesId() == null ? 0 : this.getLndcasesId() .hashCode()); result = 37 * result + (getParcelNo() == null ? 0 : this.getParcelNo().hashCode()); result = 37 * result + (getParcelBlk() == null ? 0 : this.getParcelBlk().hashCode()); result = 37 * result + (getParcelGrp() == null ? 0 : this.getParcelGrp().hashCode()); return result; } } </code></pre> <p>This is my function:</p> <pre><code>public String saveUseCases(UseCases useCases, String action,String no,String blk,String grp) { String result = ""; String[] list=useCases.getParcel().getParcelNo().split("-"); UseCases useCase=new UseCases(new UseCasesId(useCases.getUrbanPlan().getUpaId(),useCases.getLandCases().getLndcasesId(),no,blk,grp)); useCase.setUcaseIssuedate(useCases.getUcaseIssuedate()); useCase.setUcaseDocno(useCases.getUcaseDocno()); useCase.setUcaseNote(useCases.getUcaseNote()); useCase.setUcasedatesys(new Date()); try { if (action.equals("SAVE")) { useCasesDaoImpl.save(useCase); result = useCases.getId().getParcelNo(); } } catch (Exception e) { e.printStackTrace(); return null; } return result; } </code></pre> <p>as I alredy said I can insert a new record in the table but a have also this error :</p> <pre><code>15:53:59,088 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) java.lang.ClassCastException: com.dq.hibernate.model.UseCasesId cannot be cast to java.lang.String 15:53:59,091 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at com.dq.dao.GenericDao.save(Unknown Source) 15:53:59,094 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at com.dq.urbanplanning.web.manager.impl.UseCasesManagerImpl.saveUseCases(UseCasesManagerImpl.java:77) 15:53:59,096 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at com.dq.urbanplanning.web.dwr.UseCasesService.saveUseCases(UseCasesService.java:14) 15:53:59,098 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 15:53:59,104 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 15:53:59,106 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 15:53:59,113 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at java.lang.reflect.Method.invoke(Method.java:597) 15:53:59,115 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.impl.CreatorModule$1.doFilter(CreatorModule.java:229) 15:53:59,117 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.impl.CreatorModule.executeMethod(CreatorModule.java:241) 15:53:59,119 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:379) 15:53:59,121 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:332) 15:53:59,123 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.dwrp.BaseCallHandler.handle(BaseCallHandler.java:104) 15:53:59,129 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:120) 15:53:59,131 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:141) 15:53:59,133 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) 15:53:59,144 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 15:53:59,147 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) 15:53:59,149 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) 15:53:59,151 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 15:53:59,153 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) 15:53:59,155 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) 15:53:59,158 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,161 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) 15:53:59,164 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,168 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) 15:53:59,170 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,174 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) 15:53:59,177 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,179 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:150) 15:53:59,182 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,185 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) 15:53:59,188 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,191 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91) 15:53:59,193 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,196 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) 15:53:59,199 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,207 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) 15:53:59,210 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,213 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) 15:53:59,216 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 15:53:59,218 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,221 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) 15:53:59,223 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 15:53:59,226 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) 15:53:59,228 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 15:53:59,231 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 15:53:59,233 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 15:53:59,235 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) 15:53:59,236 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) 15:53:59,238 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) 15:53:59,240 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) 15:53:59,243 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) 15:53:59,245 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) 15:53:59,247 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 15:53:59,249 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 15:53:59,252 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) 15:53:59,256 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) 15:53:59,258 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) 15:53:59,260 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) 15:53:59,262 ERROR [stderr] (http-localhost-127.0.0.1-8080-6) at java.lang.Thread.run(Thread.java:662) </code></pre> <p>the error is related to this line : useCasesDaoImpl.save(useCase); //line 77</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload