Search code examples
grailsgrails-orm

Telling GORM not to persist a property


Is there a way of telling GORM not to persist a property? I'm planning to define a confirm password property on my User class that I'll use for validation, but shouldn't be persisted.


Solution

  • Using transient key word GORM can be directed not to persist specific property.

    Following code snippets shows the use of transient proerties

    class Book {
      static transients = [ "digitalCopy" ]
    
      static constraints = {
        releaseDate(nullable: true)
      }    
    
      String author
      String title
      Date releaseDate
      File digitalCopy
    }
    

    digitalCopy property included in transient declaration notifies GORM not to persist digitalCopy