Grails :Column transformers ( like Hibernate )

428 Views Asked by At

I want to add Column transformers (read and write) like this: to a Groovy domain class in a Grails application

2

There are 2 best solutions below

0
On

Depending on what you are trying to accomplish you could use Hibernate Custom Types which is explained in the Grails Documentation (http://grails.org/doc/latest/guide/GORM.html#customHibernateTypes). There is also a great example of it in practice in the jasypt (encryption) plugin by Ted Naleid (https://bitbucket.org/tednaleid/grails-jasypt/src). In his plugin, he uses Hibernate custom types to encrypt and decrypt strings (and other data types) going into and out of the database. He delegates most of the work to the jasypt library, which can be found in many places, but this is one of them (http://grepcode.com/file/repo1.maven.org/maven2/org.jasypt/jasypt-hibernate3/1.9.0/org/jasypt/hibernate3/type/AbstractEncryptedAsStringType.java?av=f)

0
On

Writing an updated answer as my initial search landed me here. Support for Column Transformers was added shortly after this question was posed, see commit

I've verified that as of GORM 7.1.x column configs are still available to declare read and write strings to be used as hibernate column transformers. See this spec for an example on usage.