Hibernate UserType troubleshooting

I am returning to a challenge that first brought me to this forum in the middle of last year, that of exploiting Hibernate’s UserType mechanism for plugging in ones own handling of certain database table columns. I received some useful guidance then and was successful in creating a proof of concept so am hopeful I might receive some further assistance this time.

This time around I am using a slightly different approach but the target system is the same, being a large monolith application with nearly 300 tables, written using Grails and GORM/Hibernate. I have established what appears to be a reliable recipe for lifting out certain entities from the scope of GORM and changing the ‘GORM mapping’ annotation that in turn configures Hibernate to use the UserType class that I supply to take care of consuming or providing the values in the relevant columns.

This work progressed well until I have encountered an exception when applying this recipe to a new entity which indicates I’ve done something wrong. The exception is of the form:

org.springframework.orm.hibernate5.HibernateSystemException: Could not set field value [DocumentType3_groovyProxy@656efa62] value by reflection : [class a.b.HibernateMappedClass.documentType] setter of a.b.HibernateMappedClass.documentType; nested exception is org.hibernate.PropertyAccessException: Could not set field value [DocumentType3_groovyProxy@656efa62] value by reflection : [class a.b.HibernateMappedClass.documentType] setter of a.b.HibernateMappedClass.documentType
   at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:267)
   at org.grails.orm.hibernate.GrailsHibernateTemplate.convertHibernateAccessException(GrailsHibernateTemplate.java:717)

Where HibernateMappedClass represents the Domain/Entity class that is the subject of ORM, and ‘documentType’ is a property within that class that is handled by a UserType subclass.

I_think_ that this is occurring at the point where a row from the table has been read and the value from the user defined column has been retrieved and is in ‘DocumentType3_groovyProxy@656efa62’, and ready to be assigned to the appropriate property of the ‘HibernateMappedClass’. But some check is failing that is preventing that assignment from occurring.

I’ve looked quite carefully and can’t see anything that would prevent this property from being settable.

Any suggestions very welcome of how I might dig deeper into this…

Usually there is more information at the bottom of the stack trace. I’d suggest you set a break point in the debugger at the line where the exception is thrown and try to figure out why setting the field fails. Maybe it’s a class loader issue? Maybe the class returned by the UserType is of the wrong class?

Thanks, breaking on the occurrence of the causing exception did reveal more detail. The object being passed to the setter is some kind of groovy proxy around the expected type (the so called delegate member holds the expected object):

groovyProxy

I believe this was provided by my UserType ‘nullSafeGet’ implementation but that it believed was an object of the enclosed type. Some groovy magic going on here that I don’t understand - perhaps the groovy language constructs such proxy objects when groovy beans are dynamically constructed from groovy bean files - I’ve posted the same picture on a groovy forum and I am hoping someone might be able to tell me what it is and how I can programatically identify and unwrap it. I really dislike groovy…

Sorry, but I don’t know Groovy that well, so yeah, it’s best to ask this on the Groovy forums.