这是可重复的,可能是一个错误。在这个例子中,我有三个表:
付款
paymentID
日期
paymentType
信用卡
paymentID
cardNo
cardTypeID
CardType
ID
说明
付款和贷记分别是父表和子类表。代码如下:
payment.cfc
component persistent="true" table="payment" discriminatorcolumn="paymentType"{
property name="paymentID";
property name="date";
}
credit.cfc
component persistent="true" extends="payment" joincolumn="paymentID"
table="credit" discriminatorvalue="ccard"{
property name="cardNo";
property name="cardTypes" fieldtype="many-to-one" lazy="true" cfc="cardType"
fkcolumn="cardTypeID";
}
cardType.cfc
component persistent="true" table="cardType"{
property name="id";
property name="description";
property name="creditCards" fieldtype="one-to-many" lazy="extra"
type="struct" structkeycolumn="id" cfc="credit" fkcolumn="cardType";
}
错误在于与cardType.cfc的“一对多”关系。当ORM生成SQL时,它会尝试将fkcolumn应用于父类的select和where子句:
select
creditcard0_.cardType as cardType30569_1_,
creditcard0_.PaymentID as PaymentID1_,
creditcard0_.PaymentID as PaymentID30570_0_,
creditcard0_.Date as Date30570_0_,
creditcard0_1_.cardNo as cardNo30572_0_,
creditcard0_1_.cardType as cardType30572_0_
from
Payment creditcard0_
inner join
CreditCardPayment creditcard0_1_
on creditcard0_.PaymentID=creditcard0_1_.PaymentID
where
creditcard0_.cardType=?
当调用简单的entityload(“cardType”)时,这会导致很多“CardType不存在”错误。
任何人都知道为什么它不能正确地应用于子类,并且它可能是我缺少的配置设置。
提前致谢。
答案 0 :(得分:1)
所以,如果我像这样映射hbmxml文件,显然它解决了这个问题:
<map lazy="extra" name="creditCards" table="CreditCardPayment" inverse="true">
<key column="cardType"/>
<map-key column="CardNo" type="string"/>
<many-to-many unique="true" column="PaymentID" class="cfc:entities.credit"/>
</map>
答案 1 :(得分:0)
尝试将mapedSuperClass =“true”添加到付款CFC。不确定这是否会像通常那样使用mappedSuperClass用于非持久性“基础”对象。