0

I have a form that inserts into a database however before I preform the insert I check if there are existing records. I am unable to insert the record and I am getting a StackOverflow Error.

Can someone tell me what causes this error and what I can do to get rid of it? If I remove the check hasRecords the code preforms fine. Its almost like the code doesn't want to access the database at this point. I have created different types of function to preform he check here for records but at this point I keep getting the same error StackOverflow

Code

com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)

public String getMonitoringStDate(Integer crimeRecNo,
            Integer socialSecurityNumber) throws Exception {

        return this.getMonitoringStDate(crimeRecNo, socialSecurityNumber);
    }

DAO for getMonitoringStDate

public String getMonitoringStDate(Integer crimeRecNo, Integer socialSecurityNumber){

    //select the minimum start date in event there is several records although this will not be allowed
    String sql = "select IFNULL(min(monitoringStDate),'0') as monitoringStDate from tblmonitoring where crimeRecNo = ? and socialSecurityNumber = ?";

    String monitoringStDate = (String)getJdbcTemplate().queryForObject(sql, new Object[]{crimeRecNo,socialSecurityNumber}, String.class);

    return monitoringStDate;
}

I also have the following listeners registered:

Listeners

 <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>

     <listener>
         <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener> 

Code

DAO

public boolean hasMonitoringRecord(Integer crimeRecNo, Integer socialSecurityNumber){

        //select a count of monitoring records there should be only one monitoring record
        String sql = "select count(*) as monitoringStDate from tblmonitoring where crimeRecNo = ? and socialSecurityNumber = ?";

        Integer count = (Integer)getJdbcTemplate().queryForObject(sql, new Object[]{crimeRecNo,socialSecurityNumber}, Integer.class);

        if(count > 0 ){

            return true;
        }else{
            return false;
        }
    }

Controller

if(result.hasErrors()){

    myMonitoringTypeList.put("monitoringTypeList",this.monitoringTypeManager.getListOfMonitoringType());
    model.addAttribute("icon", "ui-icon ui-icon-circle-close");
    model.addAttribute("results", "Error: Unable to Save Record!");
    model.addAttribute("monitoringType",myMonitoringTypeList);
    model.addAttribute("monitoring",monitoring);
    model.addAttribute("records", session.getAttribute("records"));
    model.addAttribute("crimeRecNo",session.getAttribute("crimeRecNo"));


    //return the user to the page they were on initially not the first page but the one with the error
    return new ModelAndView("monitoringList","page",session.getAttribute("page"));
}else{

    int crimeRecNo = monitoring.getCrimeRecNo();
    int socialSecurityNumber = monitoring.getSocialSecurityNumber();

        logger.info("No errors going to process records");
        logger.info("CrimeRecNo is " + monitoring.getCrimeRecNo());
        logger.info("SocialSecurity Number  is " + monitoring.getSocialSecurityNumber());
        //check if a record already exists. if one exist do an update else do an insert
        //to check if the record exists we can simply get the start date 
        String dbMonitoringStDate = monitoringManager.getMonitoringStDate(crimeRecNo,socialSecurityNumber);

        logger.info("The dbMonitoringStDate is " + dbMonitoringStDate);

        if(monitoringManager.hasMonitoringRecord(crimeRecNo, socialSecurityNumber)){
            logger.info("Has monitoring record");
            //do an update

            monitoringManager.updateMonitoringRecord(monitoring);
            model.addAttribute("icon", "ui-icon ui-icon-circle-check");
            model.addAttribute("results", "Record Was Updated");
        }else {
            logger.info("Does not have monitoring record");
            //do an insert
            monitoringManager.saveMonitoringRecord(monitoring);
            model.addAttribute("icon", "ui-icon ui-icon-circle-check");
            model.addAttribute("results", "Record Was Saved");
        }       

Error

7035 [http-bio-8084-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet  - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@6f138f45
7035 [http-bio-8084-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet  - Could not complete request
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    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:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    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:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.StackOverflowError
    at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
    at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
    at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
    at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
    at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
4

1 回答 1

2

Look at your method definition:

public String getMonitoringStDate(Integer crimeRecNo,
                                  Integer socialSecurityNumber) throws Exception {
    return this.getMonitoringStDate(crimeRecNo, socialSecurityNumber);
}

The only thing this method does is calling itself. So obviously, you have an infinite recursion loop.

于 2013-05-04T21:55:39.643 回答