开发者

ColdFusion ORM relationship mapping 'one-to-many' issue when mapped to subclass

This is repeatable and may be a bug. For this example I have three tables:

Payment

paymentID

date

paymentType

Credit

paymentID

cardNo

cardTypeID

CardType

ID

Description

Payment and Credit are parent and subclass tables respectively. The code is as follows:

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";
}  

The error lay with the "one-to-many" relationship off of cardType.cfc. When ORM generates the SQL, it tries to apply the fkcolumn to the select and where clauses to the parent class:

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=?  

This causes a lot of "CardType does not exist" errors when a simple entityload("cardType") is called.

Anyone have any idea why it would not apply it correctly to the child class and is it possibly a configuration setting I am missing.

Thanks in advance.


So, If I map the hbmxml file like so, apparently it fixes the issue:

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


Try adding mapedSuperClass="true" to the Payment CFC. Not sure if this will work as typically I have used mappedSuperClass for non persistent 'base' objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜