在我们的旧系统(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
}
}
我建议您更改DB中的表以处理IDS(20)。并从域类定义和映射中删除ID。Gorm将为您完成其余工作。
我在此链接中找到了问题的解决方案:将ID映射到另一种类型
我刚刚在类中明确声明ID为INT。正如我在链接中能理解的那样,我什至不需要声明映射中的类型。
class PBuff {
int id
String sawMill
String status
String product
String length
static mapping = {
id column: 'id', type: 'integer'
}
static constraints = {
status(inList:["Preliminary","Activ","Finished","Cancelled"])
sawMill nullable: true
status nullable: true
product nullable: true
length nullable: true
}
}