0

我想将数据插入到包含复合键的表中。

我使用休眠 HQL。

我生成了一个 hbm 和 Java 类,并开发了一个函数以将新记录插入表中

到达插入新记录但同时会产生异常

这是用例.hbm

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 7 ao?t 2013 15:46:08 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="com.dq.hibernate.model.UseCases" table="USE_CASES">
          <composite-id name="id" class="com.dq.hibernate.model.UseCasesId">
            <key-property name="upaId" type="string">
                <column name="UPA_ID" length="15" />
            </key-property>
            <key-property name="lndcasesId" type="string">
                <column name="LNDCASES_ID" length="40" />
            </key-property>
            <key-property name="parcelNo" type="string">
                <column name="PARCEL_NO" length="20" />
            </key-property>
            <key-property name="parcelBlk" type="string">
                <column name="PARCEL_BLK" length="3" />
            </key-property>
            <key-property name="parcelGrp" type="string">
                <column name="PARCEL_GRP" length="5" />
            </key-property>
        </composite-id>
        <many-to-one name="urbanPlan" class="com.dq.hibernate.model.UrbanPlan" update="false" insert="false" fetch="select">
            <column name="UPA_ID" length="15"/>
        </many-to-one>
        <many-to-one name="parcel" class="com.dq.hibernate.model.Parcel" update="false" insert="false" fetch="select">
            <column name="PARCEL_NO" length="20" />
            <column name="PARCEL_BLK" length="3" />
            <column name="PARCEL_GRP" length="5" />
        </many-to-one>
        <many-to-one name="landCases" class="com.dq.hibernate.model.LandCases" update="false" insert="false" fetch="select">
            <column name="LNDCASES_ID" length="40"  not-null="true"/>
        </many-to-one>
        <property name="ucaseOrderno" type="string">
            <column name="UCASE_ORDERNO" length="20" />
        </property>
        <property name="ucaseIssuedate" type="date">
            <column name="UCASE_ISSUEDATE" length="7"/>
        </property>
        <property name="ucaseDocno" type="string">
            <column name="UCASE_DOCNO" length="20" />
        </property>
        <property name="ucaseDesc" type="string">
            <column name="UCASE_DESC" length="500" />
        </property>
        <property name="ucasedatesys" type="date">
            <column name="UCASEDATESYS" length="7" />
        </property>
        <property name="ucaseIssuedatehj" type="string">
            <column name="UCASE_ISSUEDATEHJ" length="10" />
        </property>
         <property name="ucaseNote" type="string">
            <column name="UCASE_NOTE" length="500" />
        </property>
    </class>
</hibernate-mapping>

这是 UseCases.java

package com.dq.hibernate.model;

// Generated 7 ao&#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;
    }

}

用例ID.java:

package com.dq.hibernate.model;

// Generated 7 ao&#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 && castOther.getupaId() != null && this
                .getupaId().equals(castOther.getupaId())))
                && ((this.getLndcasesId() == castOther.getLndcasesId()) || (this
                        .getLndcasesId() != null
                        && castOther.getLndcasesId() != null && this
                        .getLndcasesId().equals(castOther.getLndcasesId())))
                && ((this.getParcelNo() == castOther.getParcelNo()) || (this
                        .getParcelNo() != null
                        && castOther.getParcelNo() != null && this
                        .getParcelNo().equals(castOther.getParcelNo())))
                && ((this.getParcelBlk() == castOther.getParcelBlk()) || (this
                        .getParcelBlk() != null
                        && castOther.getParcelBlk() != null && this
                        .getParcelBlk().equals(castOther.getParcelBlk())))
                && ((this.getParcelGrp() == castOther.getParcelGrp()) || (this
                        .getParcelGrp() != null
                        && castOther.getParcelGrp() != null && 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;
    }

}

这是我的功能:

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;
    }

正如我已经说过的,我可以在表中插入一条新记录,但也有这个错误:

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)

错误与这一行有关:useCasesDaoImpl.save(useCase); //第 77 行

4

0 回答 0