0
votes

I have an older project running Grails 1.3.7, in the domain class (ex. Patients) I added a new field (boolean disabled, nullable is true).

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

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

When I run application, a query to get all the patients belonging to a hospital now throws java.lang.IllegalArgumentException. Removing the new field "disabled", and application runs fine.

Basically the code that causes the error is similar to below:

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

Here's the error:

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) at java.lang.Thread.run(Thread.java:662)

I appreciate any help or suggestion. This has been bugging me for a few hours now.

1
You can't have a boolean property that is nullable, you need to use Boolean instead.Ian Roberts
Thanks so much. That was the problem.ibaralf
I've made the comment into an answer.Ian Roberts

1 Answers

2
votes

Properties of primitive types such as boolean can't be nullable, you need to use the wrapper class (Boolean) instead.