I have this code in my grails application:
article.findings.find { it.findingId.equals(findingId) }
that throws exception:
java.lang.NullPointerException: Cannot get property 'findingId' on null object.
Article table has a association of type : hasMany findings (List findings).
I've search in the database for:
- having an entry in article table with given article id
- having entries in findings table for given article id, all entries there have of course finding_id. Between those entries there is my entry with given finding_id.
In the database all seems good. Any idea why?
The problem was that on finding table, there is a column named findings_idx that should have values from 0 to noOfFindings-1 but in reality for that particular article the findings_idx was missing for the first entry (it was probably deleted from db). Somehow gorm/hibernate/grails expects the indexes to start from 0.