Error persisting groovy loaded entites
===

I have a problem in persisting groovy loaded entities. From debugging, I found that the session factory is able to load the classes. But it fails when saving the entity with the following error.


    Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred while calling setter of com.poc.obj1.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.poc.obj1.id
    	at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
    	at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)



    Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of poc.obj1.id
    	at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:128)
    	at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:267)


    Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)


Where poc.obj1 is the entity and the id is the 'id' attribute annotated with @Id and the table is also created in the database to store the entity.

The groovy class is given below.


    package poc;
    
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.GeneratedValue;
    
    @Entity
    public class obj1{
    @Id
    @GeneratedValue
    public java.lang.Long getId(){return id;}
    
    public void setId(java.lang.Long id){this.id = id;}
    
    
    java.lang.Long id;
    String prop1;
    String prop2;
    }

It is a very simple class with no relationships.

But the following code works fine. ie properties are settable.

		    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(obj);
		    beanWrapper.setPropertyValue("prop1", "prop1");
		    beanWrapper.setPropertyValue("prop2", "prop2");
		    beanWrapper.setPropertyValue("id", 10L);


PS: I use Groovy 1.6, Spring 3.1 and hibernate 3.6