【发布时间】:2017-03-04 09:46:18
【问题描述】:
在我们的遗留系统 (MSSQL) 中,我们使用 int 作为 id 的类型,我不想干扰它,所以我像这样更改类型:
static mapping = {
id column: "id", type: 'int'
但是在我创建一些示例记录的引导程序中,它不再起作用。 错误信息:
Configuring Spring Security UI ...
... finished configuring Spring Security UI
2017-03-04 10:31:20.381 ERROR --- [ main] o.h.p.access.spi.SetterMethodImpl : HHH000123: IllegalArgumentException in class: com.buffer.ProdBuffer, setter method of property: id
2017-03-04 10:31:20.385 ERROR --- [ main] o.h.p.access.spi.SetterMethodImpl : HHH000091: Expected type: java.lang.Long, actual value: java.lang.Integer
2017-03-04 10:31:20.419 ERROR --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.orm.hibernate5.HibernateSystemException: IllegalArgumentException occurred while calling setter for property [com.buffer.ProdBuffer.id (expected type = java.lang.Long)]; target = [com.buffer.ProdBuffer : (unsaved)], property value = [1] setter of com.buffer.ProdBuffer.id; nested exception is IllegalArgumentException occurred while calling setter for property [com.buffer.ProdBuffer.id (expected type = java.lang.Long)]; target = [com.buffer.ProdBuffer : (unsaved)], property value = [1]
at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:296)
at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:661)
at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:247)
at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:187)
看起来我错过了什么……除了更改“静态映射”中的类型之外,我还需要做些什么吗?
类的一部分:
class ProdBuffer {
String status
String product
String length
int productNo
static mapping = {
table 'LOBuffertv2'
id column: "id", type: 'integer'
product column: "Produkt", sqltype: "char", length: 150
length column: "Length", sqltype: "char", length: 25
productNo column: "ProductNo"
}
static constraints = {
status(inList:["Preliminary","Activ","Finished","Cancelled"])
status nullable: true
product nullable: true
length nullable: true
productNo nullable: true
}
}
【问题讨论】:
-
试试
id column: "id", type: 'integer' -
阅读我的答案我是如何解决的。
标签: grails grails-orm create-table