【问题标题】:Grails: Adding new field in Domain class causes crashGrails:在域类中添加新字段会导致崩溃
【发布时间】:2012-10-13 21:34:23
【问题描述】:

我有一个运行 Grails 1.3.7 的旧项目,在域类(例如患者)中,我添加了一个新字段(布尔禁用,可为空为真)。

class Hospital {
   hasMany = [patients: Patient]
   string name

class Patient 
   string name
   string address
   boolean disabled  // Added this new field

当我运行应用程序时,获取属于医院的所有患者的查询现在会引发 java.lang.IllegalArgumentException。删除“禁用”的新字段,应用程序运行正常。

基本上导致错误的代码如下:

def h = Hospital.get(20)
h.patients   // This causes error below. No error if I remove the new field in domain

这是错误:

Stacktrace follows:
java.lang.IllegalArgumentException
    at com.x.model.Patient_$$_javassist_26.hashCode(Patient_$$_javassist_26.java)
    at java.util.HashMap.put(HashMap.java:372)
    at java.util.HashSet.add(HashSet.java:200)
    at java.util.AbstractCollection.addAll(AbstractCollection.java:305)
    at com.x.service.QueryService$_getPatientsByHospitals_closure13.doCall(QueryService.groovy:183)
    at com.x.service.QueryService.getPatientsByHospitals(QueryService.groovy:180)
    at com.x.service.QueryService$$FastClassByCGLIB$$a2fb92c6.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at com.x.service.QueryService$$EnhancerByCGLIB$$6756b2a.getPatientsByHospitals(<generated>)
    at com.x.service.QueryService$getPatientsHospitals.call(Unknown Source)
    at com.x.service.PatientsOverviewService.createSummaryRow(PatientsOverviewService.groovy:366)
    at com.x.service.PatientsOverviewService$_getPatientsSummaries_closure9.doCall(PatientsOverviewService.groovy:306)
    at com.x.service.PatientsOverviewService.getPatientsSummaries(PatientsOverviewService.groovy:296)
    at com.x.service.PatientsOverviewService$getPatientsSummaries.callCurrent(Unknown Source)
    at com.x.service.PatientsOverviewService.getPatientsOverview(PatientsOverviewService.groovy:50)
    at com.x.service.PatientsOverviewService$$FastClassByCGLIB$$15a92775.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

com.x.ui.PatientsOverviewController$_closure2.doCall(PatientsOverviewController.groovy) 在 java.lang.Thread.run(Thread.java:662)

感谢任何帮助或建议。这已经困扰了我几个小时了。

【问题讨论】:

  • 你不能有一个可以为空的boolean属性,你需要使用Boolean来代替。
  • 非常感谢。这就是问题所在。
  • 我已经把评论变成了答案。

标签: grails grails-orm grails-domain-class


【解决方案1】:

boolean 等原始类型的属性不能为空,您需要改用包装类 (Boolean)。

【讨论】:

    猜你喜欢
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2015-04-17
    • 2010-10-13
    • 2013-05-28
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多