问题更新Grails域类

时间:2013-09-12 17:35:16

标签: hibernate grails gorm grails-domain-class

我遇到了Grails Domain类的简单更新问题,我真的需要进行健全性检查。我的域类是

class Container implements Serializable{

String barcode
Float tare
static hasOne = [containerContent:ContainerContent, containerSolvent:ContainerSolvent]

static constraints = {
    barcode blank: false, nullable: false, unique: true, size: 0..100
    containerSolvent blank: true, nullable: true, unique: true
    containerContent blank: true, nullable: true, unique: true
    tare blank: true, nullable: true
}}

当我尝试以下列方式更新容器属性“皮重”时,我收到错误(如下)

myFoundContainer = Container.findByBarcode(contents.get("barcode"))
def myContainer = Container.get(myFoundContainer.id )
def myTare = contents.get("tare")

try{
              myContainer.lock()
              myContainer.tare = myTare
              myContainer.save(flush:true)
    }
catch (org.springframework.dao.OptimisticLockingFailureException e) {
               println(e)
    }

然后我得到错误:

没有为参数1指定值 java.sql.SQLException

我假设它是指构造函数中的Container id?但我认为在更新期间这不重要。

在控制台中,我还看到以下消息:

Hibernate:从容器中选择id,其中id =?和版本=?更新

有人想过,这是否与任何约束“hasOne”

有关

如果有帮助,我正在使用MySQL数据库。感谢您的帮助。

  No value specified for parameter 1. Stacktrace follows:
Message: No value specified for parameter 1
    Line | Method
->> 1074 | createSQLException    in com.mysql.jdbc.SQLError
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    988 | createSQLException    in     ''
|    974 | createSQLException .  in     ''
|    919 | createSQLException    in     ''
|   2611 | checkAllParametersSet in com.mysql.jdbc.PreparedStatement
|   2586 | fillSendPacket        in     ''
|   2510 | fillSendPacket . . .  in     ''
|   2259 | executeQuery          in     ''
|     96 | executeQuery . . . .  in org.apache.commons.dbcp.DelegatingPreparedStatement
|    358 | uploadMethod          in com.sagerx.UpdateContainerStatusUponReceiptService$$EOHFXFJX
|     24 | uploadFile . . . . .  in com.sagerx.UpdateContainerStatusController
|    195 | doFilter              in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . .  in grails.plugin.cache.web.filter.AbstractFilter
|   1110 | runWorker             in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                   in java.lang.Thread

1 个答案:

答案 0 :(得分:4)

这可能与此Grails JIRA Issue(此question中提及)

有关

此问题提到了在一对一关联上使用unique: true约束时发生的类似错误。尝试从containerSolventcontainerContent

中删除唯一约束