views:

321

answers:

1

I'm trying to use 'bindData' method and exclude one field like so:

bindData(person, params, [exclude: ['responseItems']]);

I thought that by listing the 'exclude' parameter, when bindData iterates over 'params', it would ignore the key-value pair specified in the array but it doesn't appear so.

Instead, I'm getting an error:

org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type for class com.mydomain.project.yatta.ResponseItem. Expected: class java.lang.Integer, got class java.lang.String; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.mydomain.project.yatta.ResponseItem. Expected: class java.lang.Integer, got class java.lang.String

Both of the POJOs used in the bind (and mapped in grails-app/conf/hibernate/hibernate.cfg.xml) is defined as:

public class Person implements java.io.Serializable {
    private int id;
    private long version;
    private String name;
    private Date createDate;

    private Set responseItems = new HashSet(0);

    // class constructors here

    public Set getResponseItems()
    {
        return this.responseItems;
    }

    public void setResponseItems(Set responseItems)
    {
        this.responseItems = responseItems;
    }

    // rest of the getters for the instance variables
}

public class ResponseItem implements java.io.Serializable {
    private int id;
    private long version;
    private Person person; // reference back to parent
    private String label;

    private Set someChildCollection = new HashSet(0);

    // class constructors, getters and setter for each instance variables here
}

The incoming params look like:

2009-12-04 09:50:56,438 [9321358@qtp0-2] INFO  controller.PersonController  - 
params: [name:"Sally Mae", action:save, createDate: "2009-12-04 09:50:00", 
title:almost there?, controller:Person, revealIdentity:on, 
responseItemId:[692, 693], responseItems:[one, two], id:208]

If I switch to using 'include' and list only the fields I want, I still get the same error.

I'm using Grails 1.1 and prior to my upgrade from 1.0, this was working and there has been no change in the POJO or the mappings.

A: 

Are you using standard Grails domain classes or do you use legacy java classes for this? The error message you posted looks more like a ORM mapping problem than a data binding problem. Please post the code of your domain classes Person and ResponseItem.

Stefan
I've updated the question with the domain class code.
Robin Jamieson
Since you're using POJOs, please also provide your hibernate mapping configuration, esp the id definition.Try to use 'Integer' instead of 'int' for the id fields in your POJO domain classes as a first shot.
Stefan