bsqmla
bsqmla
2017-11-26 09:30

JPA一对多的问题,报错情况也在里面

20
  • 前端
  • jpa

这是前端页面的代码

 <input type="text" name="employeeExperiences[0].startTime" class="sr_input">
    <input type="text" name="employeeExperiences[0].leaveTime" class="sr_input">
    <input type="text" name="employeeExperiences[0].companyName" class="sr_input">
    <input type="text" name="employeeExperiences[0].worked" class="sr_input" >
    <input type="text" name="employeeExperiences[0].positions" class="sr_

这是一方的实体类代码

 @Entity
@Table(name = "t_employee")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "t_employee_sequence")
public class Employee extends BaseEntity{

    private static final long serialVersionUID = -2990277225492385248L;
    private String name;
    private Integer sex;
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date birthDate;
    private String idNumber;
    private String homeAddress;
    private String zipCode;
    private String birthPlace;
    private String ethnic;
    private String languageAndLevel;
    private String academicGroups;
    private List<EmployeeExperience> employeeExperiences;//


    @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.MERGE,mappedBy="employee")
    public List<EmployeeExperience> getEmployeeExperiences() {
        return employeeExperiences;
    }
    public void setEmployeeExperiences(List<EmployeeExperience> employeeExperiences) {
        this.employeeExperiences = employeeExperiences;
    }

以下是多方的实体

 @Entity
@Table(name="t_employee_experience")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "t_employee_experience_sequence")
public class EmployeeExperience extends BaseEntity{
    /**
     * 
     */
    private static final long serialVersionUID = 4370501941190181313L;
    private Employee employee;
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date startTime;
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date leaveTime;
    private String companyName;
    private String worked;
    private String positions;

    @ManyToOne(cascade=CascadeType.MERGE)
    @JoinColumn(name="employee")
    public Employee getEmployee() {
        return employee;
    }
    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

以下是Controller的代码

 @RequestMapping("rygl_save")
    public String rygl_save(Employee employee,ModelMap model,HttpServletResponse response,EmployeeExperience[] employeeExperiences){
        response.setContentType("text/html; charset=UTF-8");

        for(EmployeeExperience ee:employeeExperiences){
            ee.setEmployee(employee);
        }
        employee.setEmployeeExperiences(Arrays.asList(employeeExperiences));



        employeeService.save(employee);

以下是发送请求后输出的报错信息

 org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [[Lnet.uvct.entity.EmployeeExperience;]: No default constructor found; nested exception is java.lang.NoSuchMethodException: [Lnet.uvct.entity.EmployeeExperience;.<init>()
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:108)
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:136)
    at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:81)
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:101)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:270)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at net.uvct.filter.SiteStatusFilter.doFilterInternal(SiteStatusFilter.java:36)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NoSuchMethodException: [Lnet.uvct.entity.EmployeeExperience;.<init>()
    at java.lang.Class.getConstructor0(Class.java:2810)
    at java.lang.Class.getDeclaredConstructor(Class.java:2053)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
    ... 45 more

这个报错信息很奇怪,我的类名是net.uvct.entity.EmployeeExperience;,但是报错前面多了"[L",我用全局搜索,也没有这个报错的类名

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答