很多人用struts 1来休眠:非法参数异常

时间:2013-07-21 11:23:12

标签: hibernate java-ee many-to-many struts-1

我正在使用带有hibernate的Struts 1。 在我的hibernate实体中添加多对多关系之后,save不能用于此错误:

java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1776)
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1762)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1651)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1680)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1039)
at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:493)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:796)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1192)
at org.broker.web.CustomizedActionServlet.process(CustomizedActionServlet.java:522)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:430)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.broker.web.UnicodeFilter.doFilter(UnicodeFilter.java:28)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.broker.web.MessageFilter.doFilter(MessageFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.broker.util.GZIPFilter.doFilter(GZIPFilter.java:19)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:662)

我在.hbm.xml中添加:

 <set name="customerGroupsForReport" table="APPUSER_CUSTOMER_GROUP_REPORT"
        inverse="false" lazy="true" fetch="select" cascade="all" >
        <key>
            <column name="APPUSER_ID" not-null="true" />
        </key>
        <many-to-many entity-name="org.broker.model.CustomerGroup">
            <column name="CUSTOMER_GROUP_ID" not-null="true" />
        </many-to-many>
    </set>
<。> .java实体

 private Set <CustomerGroup> customerGroupsForReport = new HashSet<CustomerGroup>(0);
    public Set<CustomerGroup> getCustomerGroupsForReport() {
        return customerGroupsForReport;
    }

    public void setCustomerGroupsForReport(Set<CustomerGroup> customerGroupsForReport) {
        this.customerGroupsForReport = customerGroupsForReport;
    }
<。>在.jsp中:

 <html:select property="appUser.customerGroupsForReport" multiple="true">
               <html:options collection="customerGroups" labelProperty="customerGroupName" property="customerGroupId"/>
          </html:select>

在行动类中:

        request.setAttribute("customerGroups", manager.findObjects(CustomerGroup.class,"customerGroupName"));

我的问题在哪里?

1 个答案:

答案 0 :(得分:1)

当您使用多选下拉列表时,
假设customerGroupId是数字,用户已选择1和2 customerGroupId
appUser.customerGroupsForReport参数将作为
传递 appUser.customerGroupsForReport = 1
appUser.customerGroupsForReport = 2

考虑到上述情况,我建议您将“customerGroupsForReport”属性绑定到DynaActionForm配置中的数组,例如Long [](如果您的customerGroupId很长)
然后转换回Action类中的Set。