david wrote:
Off the top of my head. Try:
/**
*
* @hibernate.many-to-one class="org.apfuse.model.Equipment"
* cascade="none"
* not-null="false"
* @hibernate.column name="MKTG_EQMT_GRP_ID"
* @hibernate.column name="MKTG_EQMT_SGRP_ID"
*/
Hello,
I have a question related to this earlier question about my RateProposal mapping to an Equipment class involving composite-id's. In the above example, this worked *nicely* and the above xdoclet tagging resulted in a mapping file that worked just fine and that looked like this:
<many-to-one
name="equipment"
class="com.uprr.app.qts.domain.model.Equipment"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="MKTG_EQMT_GRP_ID"
/>
<column
name="MKTG_EQMT_SGRP_ID"
/>
</many-to-one>
This is a many-to-one mapping that accompanies a simple getter / setter that sets the Equipment object like this, etc. (also has an analogous setter):
public Equipment getEquipment() {
return equipment;
}
We recently had cause to make this a many-to-many relationship between RateProposal and Equipment so I chose to implement it as 2 one-to-many relationships with an intervening entity class & table. I have used a several of these constructs but have never had to use one in conjunction with a composite id which is used by the Equipment class and I suspect that this is the crux of my problem, & though I don't see anything obviously wrong with mappings, I must be missing something.
After creating an intervening entity class to act as the link table class between RateProposal and Equipment, called RateProposalEquipment, I set up the mappings as I had other m:m with intervening link table entities but I'm getting this error. I suspect that it may have to do something different with the composite key class as it's mentioned in this error:
net.sf.hibernate.MappingException: collection foreign key mapping has wrong number of columns: com.uprr.app.qts.domain.model.Equipment.rateProposalEquipment type: com.uprr.app.qts.domain.model.EquipmentSubGroupId
Here is the new mapping for RateProposal to the RateProposalEquipment link table intervening entity, from RateProposal.hbm.xml:
<set
name="rateProposalEquipment"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
>
<column
name="RATE_PRPL_ID"
not-null="true"
/>
</key>
<one-to-many
class="com.uprr.app.qts.domain.model.RateProposalEquipment"
/>
</set>
This looks exactly the same as the other m:m's I implemented but none of the others have a composite key class as Equipment does.
Here's the many-to-one mapping in RateProposalEquipment.hbm.xml, which looks just like old the one used to look in RateProposal.hbm.xml and which I thought would work with my composite key class, called "EquipmentSubGroupId". I would think the error is either here or in the Equipment.hbm.xml, shown later below. This style of many-to-one mapping is *just* like that shown above which worked fine in the RateProposal class, so I thought it would work here too. The two columns shown below are mapped via the composite key class, just as they were above:
<many-to-one
name="equipment"
class="com.uprr.app.qts.domain.model.Equipment"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
>
<column
name="MKTG_EQMT_GRP_ID"
/>
<column
name="MKTG_EQMT_SGRP_ID"
/>
</many-to-one>
This class also has a many-to-one mapping to the RateProposal class that is similar:
<many-to-one
name="rateProposal"
class="com.uprr.app.qts.domain.model.RateProposal"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="RATE_PRPL_ID"
not-null="true"
/>
All of these constructs I've used before successfully, but not with a composite key class in the mix...
Now, here's the one-to-many mapping in Equipment, which is where I suspect the problem is, based on the error above, but I don't see what's wrong with it [could be a newbie question but I couldn't find this in the archives -- it *must* be there but...?]. This is from Equipment.hbm.xml:
<set
name="rateProposalEquipment"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>
<key
>
<column
name="RATE_PRPL_ID"
not-null="true"
/>
</key>
<one-to-many
class="com.uprr.app.qts.domain.model.RateProposalEquipment"
/>
</set>
The error above seems to indicate a problem with the set valued attribute of the Equipment class, which holds classes of type RateProposalEquipment and it's saying that there are the wrong number of columns, but everywhere I have looked the columns appear correct -- there's only one case where there should be 2 columns, which is in the many-to-one mapping in RateProposalEquipment.hbm.xml, and there *ARE* 2 columns there so I'm unclear on what is wrong with this. All other references use one column and ther eis one column spec'ed for all these. Is there some special collection oriented construct I need to use somewhere around here? Any help would be appreciated!
Thanks again,
-=j=-