Antony Prince
Antony Prince

Reputation: 319

Grails: Transients property in Constraints.groovy

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']

Upvotes: 3

Views: 733

Answers (2)

Antony Prince
Antony Prince

Reputation: 319

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

Upvotes: 2

Ian Roberts
Ian Roberts

Reputation: 122364

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).

Upvotes: 0

Related Questions