我在Grails应用程序中尝试保存新记录时收到arrayIndexOutOfBounds异常。
我已将问题缩小到只能保存8个字段。
这是我的域类:
package nhvr
class NhvrJourny {
static constraints = {
nhvrNo nullable:true
journeyId nullable:true
width nullable:true
vLength nullable:true
height nullable:true
rearOverhang nullable:true
}
Long nhvrNo
String journeyId
String title
BigDecimal width
BigDecimal vLength
BigDecimal height
BigDecimal rearOverhang
String toString(){
return "$nhvrNo $title"
}
}
我通过服务保存数据。该方法如下所示:
def saveJourny(Map nhvrJourneyPars) {
if (nhvrJourneyPars?.dateArchived)
da = df.parse(nhvrJourneyPars.dateArchived)
Map journeyPars = [
journeyId : nhvrJourneyPars.journeyId,
title : nhvrJourneyPars.title,
nhvrNo : nhvrJourneyPars.nhvrNo,
width : nhvrJourneyPars.width,
vLength : nhvrJourneyPars.vLength,
height : nhvrJourneyPars.height,
rearOverhang : nhvrJourneyPars.rearOverhang
]
NhvrJourny nhvrJournyInstance = new NhvrJourny(journeyPars)
println "journeyPars:"
journeyPars.each{
println "${it.key}: ${it.value}"
}
if (nhvrJournyInstance == null) {
println "nhvrJournyInstance is null"
notFound()
return
}
if (!nhvrJournyInstance.validate()) {
if (nhvrJournyInstance.hasErrors()) {
println "Errors: ${nhvrJournyInstance.errors.allErrors}"
respond nhvrJournyInstance.errors, view: 'create'
return
}
}
else{
println "No errors in nhvrJourneysInstance."
}
println "nhvrJournyInstance.properties"
nhvrJournyInstance.properties.each{
println " ${it.key}: ${it.value}"
}
nhvrJournyInstance.save(flush:true)
return nhvrJournyInstance
}
我可以看到传入的数据并且看起来没问题:
nhvrJournyInstance: {"journeyId":"j1","title":"test","nhvrNo":"2","width":3,"height":3,"vLength":21,"rearOverhang":1}
当我调用nhvrJournyInstance.save(flush:true)时,这当前返回一个ArrayIndexOutOfBounds异常
如果我从Domain类中删除其中一个字段,则会保存数据。注意:虽然只显示了七个字段,但ID和版本会自动添加。
我一直在使用windows 7上的intellij 13.1.4中的run-app进行测试 我的Grails版本是2.4.2,Java版本是1.7.0_60 该数据库是Oracle 11g,使用ojdbc6.jar
有人可以对此有所了解吗?它让我疯了。
编辑 - 这是堆栈跟踪:
14. Stacktrace follows:
Message: 14
Line | Method
->> 950 | computeBasicInfo in oracle.jdbc.driver.OracleSql
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 623 | getSqlKind in ''
| 1212 | <init> . . . . . . . . . in oracle.jdbc.driver.OraclePreparedStatement
| 28 | <init> in oracle.jdbc.driver.T4CPreparedStatement
| 68 | allocatePreparedStatement in oracle.jdbc.driver.T4CDriverExtension
| 3140 | prepareStatement in oracle.jdbc.driver.PhysicalConnection
| 3042 | prepareStatement . . . . in ''
| 6022 | prepareStatement in ''
| 699 | $tt__saveJourney . . . . in nhvr.NhvrService
| 58 | $tt__saveJourney in nhvr.NhvrJourneyController
| 198 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . . in java.lang.Thread
enter code here
答案 0 :(得分:2)
我用来连接数据库的ojdbc6.jar文件版本存在问题。
我已经下载了这个文件的另一个版本,它大了500kb,现在正在运行。
感谢Jeff的意见。