1
我有兩個領域類。一個是「合作伙伴」,另一個是「客戶」。客戶可以成爲合作伙伴的一部分,合作伙伴可以有1個或多個客戶:Grails與joinTable的一對多映射
class Customer {
Integer id
String name
static hasOne = [partner:Partner]
static mapping = {
partner joinTable:[name:'PartnerMap',column:'partner_id',key:'customer_id']
}
}
class Partner {
Integer id
static hasMany = [customers:Customer]
static mapping = {
customers joinTable:[name:'PartnerMap',column:'customer_id',key:'partner_id']
}
}
但是,每當我嘗試看看如果客戶是合作伙伴的一部分,就像這樣:
我得到以下錯誤:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select this_.customer_id as customer1_162_0_, this_.company as company162_0_, this_.display_name as display3_162_0_, this_.parent_customer_id as parent4_162_0_, this_.partner_id as partner5_162_0_, this_.server_id as server6_162_0_, this_.status as status162_0_, this_.vertical_market as vertical8_162_0_ from Customer this_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
看起來好像Grails是想PARTNER_ID是客戶查詢的一部分,它不...它是在PartnerMap表,這是應該找customer_id,t母雞從相應的partner_id獲取合作伙伴。
任何人有任何線索我做錯了什麼?
編輯:我忘了提及我正在做這與遺留數據庫表。所以我有一個合作伙伴,客戶和PartnerMap表。 PartnerMap只有一個customer_id和partner_id字段。
糟糕,我忘了提及,我正在做這與傳統的數據庫的東西...所以我必須使用預定義的表。我有一個客戶,合作伙伴和PartnerMap表。 PartnerMap只是一個customer_id和partner_id字段。這是否限制了我? – intargc 2011-01-12 23:20:31