-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: XDoclet ignoring a column for 2 column composite-id class
PostPosted: Tue Oct 05, 2004 5:49 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
Hibernate version: 2.1.3

Mapping documents:XDoclet genearated hbm files, excerpt included in post

Code between sessionFactory.openSession() and session.close(): N/A

Full stack trace of any exception that occurs:N/A

Name and version of the database you are using:MySQL 4.0.20

The generated SQL (show_sql=true):N/A

Debug level Hibernate log excerpt:N/A

Hi,

Hey gang,

I have a problem using XDoclet to map a 'Proposal' class with a many-to-one assoc. to an 'Equipment' class that has a composite-id and uses a composite identifier class. The hbm for the Equipment class using the composite identifier class looks correct and XDoclet produced no errors generating the hbm or completing the ant task succesfully. However when I put a property in the Proposal class with a many-to-one assoc. to the Equipment class it ignored one of the columns.

The XDoclet tags look like this in the Proposal class:

/**
*
* @hibernate.many-to-one class="org.apfuse.model.Equipment"
* column="MKTG_EQMT_GRP_ID"
* column="MKTG_EQMT_SGRP_ID"
* cascade="none"
* not-null="false"
*/
public Equipment getEquipment() {
return equipment;
}

Unfortunately XDoclet is ignoring the 1st column listed above, MKTG_EQMT_GRP_ID and only generates the hbm XML for the MKTG_EQMT_SGRP_ID column the result of which looks like this:

<many-to-one
name="equipment"
class="org.appfuse.model.Equipment"
cacade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="MKTG_EQMT_SGRP_ID"
not-null="false"
/>

This results in an error when constraints are applied, which is "Schema text failed, Foreign key (CDM_RATE_PRPL [MKTG_EQMT_SGRP_ID])) must have same number of columns as the referenced primary key (CDM_MKTG_EQMT_SGRP [MKTG_EQMT_GRP_ID,MKTG_EQMT_SGRP_ID])"

I tried removing the MKTG_EQMT_SGRP_ID column from the POJO XDoclet tags so only one column was mentioned and then it produced the same error but with the MKTG_EQMT_GRP_ID listed in the foreign key error text. I also scoured the hibernate FAQs & forums [especially but not limited to the tools areas] but all I found was an admonition to make sure to list the columns in the same order in all places, which is consistent with what I already had done.

Is this an issue with XDoclet or does XDoclet not support this? I *could* edit the mapping file by hand, but I'd much prefer to leave that automated, for obvious reasons, but is there a way to make this work?

Or is this an XDoclet tag user error? I checked an XDoclet book [Manning, kind of limited for hibernate] and Bauer/King's new HIA book [which is very nice, BTW] but found no mention of this.

Anybody know what's wrong here?

tia,

-=j=-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 05, 2004 9:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
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"
*/


Top
 Profile  
 
 Post subject: XDoclet ignoring a column for 2 column composite-id class
PostPosted: Wed Oct 06, 2004 10:32 am 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
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"
*/


Thanks David, that worked nicely! BTW, I've had a devil of a time finding much documentation on XDoclet for use with hibernate, the manning book spends precious little space on it, is there a better reference that you know of? The web site seems out of date, but I could be wrong...

Thanks again,

-=j=-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 9:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
There is not much information around. XDoclet project does have the basic tags etc for the latest release. I refer to standard docs and work things out by trying a few approaches. If i'm having real trouble then refer to the source code of XDoclet. There are a few exmaple applications around that are based on XDoclet so they could be usefull as well.


Top
 Profile  
 
 Post subject: Re: XDoclet ignoring a column for 2 column composite-id clas
PostPosted: Tue Nov 09, 2004 2:51 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
jackalista wrote:
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. This generated hbm mapping that worked is:

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 3:07 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
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=-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 5:09 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
OK, I figured this out, I *think*. I changed the mapping in Equipment.hbm.xml so that the key to the collection also had a composite key class, since the collection is owned by an entity with a composite key (Equipment). What's strange here is that this changes the entity referred to by the columns in the mapping from the RateProposal to the Equipment columns...?!?!?! Here's the Equipment.hbm.xml mapping, and I'm not getting an exception anymore:

Code:
        <set
            name="rateProposalEquipment"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
              >
                <column
                    name="MKTG_EQMT_GRP_ID"
                    not-null="true"
                />
                <column
                    name="MKTG_EQMT_SGRP_ID"
                    not-null="true"
                />
              </key>
             

              <one-to-many
                  class="com.uprr.app.qts.domain.model.RateProposalEquipment"
              />
        </set>


What doesn't seem intuitive to me is that the <key> element *used* to refer to the RateProposal class and it's key column, RATE_PRPL_ID, and now has switched to refer to the Equipment class and its 2 key columns. My other code for this sort of many-to-many rendering with an intervening link entity has mappings in the analogous class that refer only to the RateProposal. Are these mappings incorrect?

For ex., here's the mapping for the rateProposalParties in Party.hbm.xml, which is analogous to the Equipment.hbm.xml set mapping shown above, the only difference being that Party doesn't have a composite key class while Equipment does. I have been using code like this Party example without incident, and while there are no entities with composite keys, the key column in this set mapping refers to the RateProposal class, not the Party class; it's the Party class that would be the analog of the 2 column Equipment class in my composite key example above. Is this wrong?:

Code:
        <set
            name="rateProposalParties"
            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.RateProposalParty"
              />

        </set>


Thanks, in advance!

-=j=-


Top
 Profile  
 
 Post subject: question re: many-to-many as 2 one-to-many with link entity
PostPosted: Tue Nov 09, 2004 5:18 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
OK, I figured this out, I *think*. I changed the mapping in Equipment.hbm.xml so that the key to the collection also had a composite key class, since the collection is owned by an entity with a composite key (Equipment). What's strange here is that this changes the entity referred to by the columns in the mapping from the RateProposal to the Equipment columns...?!?!?! Here's the Equipment.hbm.xml mapping, and I'm not getting an exception anymore:

Code:
        <set
            name="rateProposalEquipment"
            lazy="false"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

              <key
              >
                <column
                    name="MKTG_EQMT_GRP_ID"
                    not-null="true"
                />
                <column
                    name="MKTG_EQMT_SGRP_ID"
                    not-null="true"
                />
              </key>
             

              <one-to-many
                  class="com.uprr.app.qts.domain.model.RateProposalEquipment"
              />
        </set>


What doesn't seem intuitive to me is that the <key> element *used* to refer to the RateProposal class and it's key column, RATE_PRPL_ID, and now has switched to refer to the Equipment class and its 2 key columns. My other code for this sort of many-to-many rendering with an intervening link entity has mappings in the analogous class that refer only to the RateProposal. Are these mappings incorrect?

For ex., here's the mapping for the rateProposalParties in Party.hbm.xml, which is analogous to the Equipment.hbm.xml set mapping shown above, the only difference being that Party doesn't have a composite key class while Equipment does. I have been using code like this Party example without incident, and while there are no entities with composite keys, the key column in this set mapping refers to the RateProposal class, not the Party class; it's the Party class that would be the analog of the 2 column Equipment class in my composite key example above. Is this wrong?:

Code:
        <set
            name="rateProposalParties"
            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.RateProposalParty"
              />

        </set>


Thanks, in advance!

-=j=-


Top
 Profile  
 
 Post subject: Re: XDoclet ignoring a column for 2 column composite-id clas
PostPosted: Wed Nov 10, 2004 9:13 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
jackalista wrote:
Thanks David, that worked nicely! BTW, I've had a devil of a time finding much documentation on XDoclet for use with hibernate, the manning book spends precious little space on it, is there a better reference that you know of? The web site seems out of date, but I could be wrong...

-=j=-


Information about hIbernate tags for xdoclet-2 plugin is generated automatically pretty oft.

http://docs.codehaus.org/pages/viewpage ... ageId=2215

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.