在我的項目中我正在使用兩個數據庫,並且兩個數據庫中的列名都不相同。所以我在配置文件中定義了一個標誌,並在域中注入了一個依賴項。我可以在groovy域注入依賴項嗎?
例如: - >
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;
}
}
是否有任何其他方式根據數據庫
,我發現了錯誤定義的列名,而執行此代碼。 的錯誤是, 「錯誤評估ORM映射阻塞域MRAffiliate沒有這樣的屬性:grailsApplication類:org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder」
@Szymon哪個grails版本是這樣的? –
grails版本:2.4.4 –
您正嘗試從靜態上下文('mapping' closure')中訪問實例變量('grailsApplication')。您無法從靜態上下文訪問任何實例狀態。該語言不允許使用它,因爲它不合情理。 –