データベースに挿入するフォームがありますが、挿入を実行する前に、既存のレコードがあるかどうかを確認します。レコードを挿入できず、StackOverflowエラーが発生します。
このエラーの原因と、それを取り除くためにできることを誰か教えてもらえますか? チェック hasRecords を削除すると、コードは正常にプリフォームされます。この時点では、コードがデータベースにアクセスしたくないようです。ここでレコードをチェックするためのさまざまなタイプの関数を作成しましたが、この時点で同じエラーStackOverflowが発生し続けます
コード
com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
public String getMonitoringStDate(Integer crimeRecNo,
Integer socialSecurityNumber) throws Exception {
return this.getMonitoringStDate(crimeRecNo, socialSecurityNumber);
}
getMonitoringStDate の DAO
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;
}
次のリスナーも登録しています。
リスナー
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
コード
ダオ
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;
}
}
コントローラ
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");
}
エラー
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)