3

I want to replace domain class in grails with a hibernate class(Rate). So constrains to hibernate class can be added by creating a file RateConstraints.groovy in src/java, and it works fine for validations of hibernate class. now i need to add transients property to hibernate class using this RateConstraints.groovy.

Eg:

Consider a java Class

class Rate {        
        Long id 
        String code         
    }

RateConstraints.groovy file in ../src/java

constraints = { 
    id ( nullable:true )
    code( nullable: false )
}

How can i add transients property in RateConstraints.groovy file

transients = ['startDate', 'endDate']
tim_yates
  • 167,322
  • 27
  • 342
  • 338
Antony Prince
  • 319
  • 4
  • 17

2 Answers2

2

Got the answer

RateConstraints.groovy file in ../src/java

transients = ['startDate', 'endDate']

Rate.metaClass.getStartDate << {-> startDate  }
Rate.metaClass.setStartDate << {it -> startDate = it }
Rate.metaClass.getEndDate << {-> endDate  }
Rate.metaClass.setEndDate << {it -> endDate = it }

constraints = { 
    id ( nullable:true )
    code( nullable: false )
}

it works

Antony Prince
  • 319
  • 4
  • 17
0

You don't. If you want to mark a property in a hibernate POJO as transient then you use the regular @Transient annotation in the POJO itself (or just don't map it at all if you're using hbm.xml).

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183