您好我收到一个非常奇怪的错误:ORA-01861:文字与格式字符串不匹配。我的所有互联网搜索都与DATE问题有关。我只是为了保存一个简单的字符串。如果您发现问题,请告诉我如何解决问题。
问题列
TREND: VARCHAR2(31, CHAR), no constraints
通过以下方式在GORM中映射:
String trend
...
static constraints = {
trend(nullable: true, blank: true)
... } ...
static mapping = {
trend column: "TREND", sqlType: "varchar(31)"
...}
问题方法:
def fix_trend(){
// There should ever only be three values found in the trend column
// of the Reports table: "TRENDING UP", "TRENDING STEADY", "TRENDING DOWN"
println "Running groovy database procedure : fix_trend"
StatusReport.list().each{
String trend = it.trend
if (trend != 'TRENDING UP' && trend != 'TRENDING STEADY' && trend != 'TRENDING DOWN'){
trend = trend?.toUpperCase()
if (trend == null){
trend = 'TRENDING STEADY'
}
else if (trend.contains('UP')){
trend = 'TRENDING UP';
}
else if (trend.contains('DOWN')){
trend = 'TRENDING DOWN';
}
else{
trend = 'TRENDING STEADY';
}
it.trend = trend;
it.save();
}
}
println "fix_trend completed"
}
该方法的目的是确保所有值都是趋势向上,趋向于向下或趋势稳定。
堆栈跟踪:
Running groovy database procedure : fix_trend
fix_trend completed
Error |
2015-01-05 10:53:02,392 [http-bio-8080-exec-4] ERROR spi.SqlExceptionHelper - ORA-01861: literal does not match format string
Error |
2015-01-05 10:53:02,481 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - SQLDataException occurred when processing request: [GET] /investigator/statusReports/selection
ORA-01861: literal does not match format string
. Stacktrace follows:
Message: ORA-01861: literal does not match format string
Line | Method
->> 439 | processError in oracle.jdbc.driver.T4CTTIoer
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 395 | processError in ''
| 802 | processError . . . . in oracle.jdbc.driver.T4C8Oall
| 436 | receive in oracle.jdbc.driver.T4CTTIfun
| 186 | doRPC . . . . . . . in ''
| 521 | doOALL in oracle.jdbc.driver.T4C8Oall
| 205 | doOall8 . . . . . . in oracle.jdbc.driver.T4CPreparedStatement
| 1008 | executeForRows in ''
| 1307 | doExecuteWithTimeout in oracle.jdbc.driver.OracleStatement
| 3449 | executeInternal in oracle.jdbc.driver.OraclePreparedStatement
| 3530 | executeUpdate . . . in ''
| 1350 | executeUpdate in oracle.jdbc.driver.OraclePreparedStatementWrapper
| 16 | selection . . . . . in investigator.StatusReportsController
| 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
答案 0 :(得分:0)
我解决了自己的问题。
表中有一个Date字段被错误地表示为Domain类中的String。即使我尝试更新VARCHAR2字段,domain_class.save()方法也会更新该domain_class的每个属性 - 因此错误与TREND字段无关,但与错误的DATE字段无关。
我通过添加到DataSource.groovy
来解决这个问题logSql = true
formatSql = true
和Config.groovy
log4j.main = {
trace 'org.hibernate.type'
debug 'org.hibernate.SQL'
...
这表明.save()生成的update语句尝试更新EVERY属性。
希望这有助于将来。