In My Project I'm using two database and the column name is different in both database. So I defined a flag in config file , and injected a dependency in domain.
Example:-->
class MRAffiliate {
transient def grailsApplication;
String companyName;
String annotations;
static mapping = {
table name: "affiliati"//, schema: "public"
id generator:'sequence', params:[sequence:'affiliati_seq']
id column: "id"//, sqlType: "int4";
if (grailsApplication.config.com.dogmasystems.postgres==true){
companyName column: "ragione_sociale";
} else {
companyName column: "ragione_sociale", sqlType: "string";
}
if (grailsApplication.config.com.dogmasystems.postgres==true){
annotations column: "annotazioni";
} else {
annotations column: "annotazioni", sqlType: "string";
}
version false;
}
}
Is there any other way to define the column name according to database
I'm getting the error , while executing this code . The error is, "Error evaluating ORM mappings block for domain MRAffiliate No such property: grailsApplication for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder"
Try Holders.grailsApplication.config.xxx
-- see this domain class which uses the config in mapping block.