org.hibernate.PropertyAccessException:调用com.span.model.Customer.custName

时间:2019-01-31 15:22:27

标签: java spring hibernate

我一直在与我的宠物项目一起工作,包括Angular,springboot和Hibernate。我很冬眠。我收到了以下异常。

  

2019-01-31 20:29:27.973错误5256 --- [nio-8900-exec-1]   o.h.p.access.spi.GetterMethodImpl:HHH000122:   类中的IllegalArgumentException:com.span.model.Customer,getter   属性方法:custName 2019-01-31 20:29:27.973 INFO 5256 ---   [nio-8900-exec-1] c.s.s.daoService.CommonServiceDaoImpl:异常   在saveCustomer中:org.hibernate.PropertyAccessException:   发生IllegalArgumentException呼叫的getter   com.span.model.Customer.custName   org.hibernate.PropertyAccessException:IllegalArgumentException   发生在调用com.span.model.Customer.custName的getter   org.hibernate.property.access.spi.GetterMethodImpl.get(GetterMethodImpl.java:65)     在   org.hibernate.property.access.spi.GetterMethodImpl.getForInsert(GetterMethodImpl.java:77)     在   org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.java:559)     在   org.hibernate.tuple.entity.PojoEntityTuplizer.getPropertyValuesToInsert(PojoEntityTuplizer.java:225)     在   org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValuesToInsert(AbstractEntityPersister.java:4999)     在   org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:271)     在   org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:200)     在   org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:131)     在   org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)     在   org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)     在   org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)     在   org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)     在   org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)     在org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:709)     在org.hibernate.internal.SessionImpl.save(SessionImpl.java:701)处   org.hibernate.internal.SessionImpl.save(SessionImpl.java:696)在   com.span.service.daoService.CommonServiceDaoImpl.saveCustomer(CommonServiceDaoImpl.java:27)     在   com.span.service.daoService.CommonServiceDaoImpl $$ FastClassBySpringCGLIB $$ cde5bb03.invoke()     在   org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)     在   org.springframework.aop.framework.CglibAopProxy $ CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)     在   org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)     在   org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)     在   org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)     在   com.span.service.daoService.CommonServiceDaoImpl $$ EnhancerBySpringCGLIB $$ b9118af.saveCustomer()     在   com.span.service.RegisterServiceImpl.registerCustomer(RegisterServiceImpl.java:18)     在   com.span.controller.HomeController.registerCustomer(HomeController.java:27)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)     在   org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)     在   org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)     在   org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)     在   org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)     在   org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)     在   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)     在   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)     在   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:660)在   org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:741)处   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:117)     在   org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:106)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)     在   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)     在   org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)     在   org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)     在   org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:834)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1417)     在   org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)     在   java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:748)造成原因:   java.lang.IllegalArgumentException:对象不是的实例   在上课   sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.hibernate.property.access.spi.GetterMethodImpl.get(GetterMethodImpl.java:42)     ... 89更多2019-01-31 20:29:27.992信息5256 --- [nio-8900-exec-1]   c.s.s.daoService.CommonServiceDaoImpl:saveCustomer结尾为   customerId:0

我在CommonServiceDaoImpl中的方法saveCustomer看起来像这样:

public int saveCustomer(Customer customer) {
  log.info("saveCustomer starts");
  try {
    customer.setCustAge(util.calculateAge(customer.getCustDob()));
    customer.setCustPass(util.getSHA(customer.getCustPass()));
    SessionFactory sessionFactory = new     
    Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    session.save(customer); 
    session.getTransaction().commit();
    session.close();        
  } catch(Exception ex) {
    log.info("Exception in saveCustomer: "+ex);
    ex.printStackTrace();
  }
    log.info("saveCustomer ends with customerId: "+customer.getCustId());
    return customer.getCustId();
  }

客户模型类如下所示:

package com.span.model;

import java.util.Date;

import lombok.Data;
import lombok.Getter;

@Data
 public class Customer {

    private int custId;
    private String custName;
    private int custAge;
    private String custGen;
    private Date custDob;
    private String custEmail;
    private String custMob;
    private String custPass;
}

控制器调用如下:

@RequestMapping(value = "/brw/registerCustomer", method = {RequestMethod.POST })
public Long registerCustomer(@RequestBody Customer customer) {
    int custId = 0;
    log.info("registerCustomer starts..." + customer);
    try {
        custId = registerService.registerCustomer(customer);
        log.info("registerCustomer ends..." + custId);
    } catch (Exception ex) {
        System.out.println("Exception is: " + ex);
        log.info("Exception is: " + ex);
    }
    return Long.valueOf(custId);
}

最后,我的休眠映射如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.span.model.Customer" table="Customer">

        <meta attribute="class-description">
            This class contains the customer detail.</meta>
        <id name="custId" type="java.lang.Integer" column="cust_id">
            <generator class="sequence-identity">
                <param name="sequence">customer_seq</param>
            </generator>
        </id>

        <property name="custName" type="string" column="cust_name" />
        <property name="custAge" column="cust_age" type="java.lang.Integer" />
        <property name="custGen" column="cust_gen" type="string" />
        <property name="custEmail" column="cust_mail" type="string" />
        <property name="custMob" column="cust_mob" type="string" />
        <property name="custPass" column="password" type="string" />
        <property name="custDob" column="cust_dob" type="java.sql.Date" />
    </class>
</hibernate-mapping>

我正在使用Oracle 12g。 请让我知道我在哪里弄错了,谢谢。

0 个答案:

没有答案