Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
dianellanunez
22 Post subject:   PostPosted: Jan 21, 2005 - 07:49 PM



Joined: Jan 21, 2005
Posts: 1

Hi, I have a table with a composite id, that's ok until this composite id is a foreign key in another table. The code generated by the hibernate tool doesn't even work.
<class name="Promotion" table="promotion">
<composite-id name="id" class="PromotionKey">
<key-property name="promoId" column="promo_id" type="java.lang.Integer"/>
<key-property name="subPromoId" column="sub_promo_id" type="java.lang.Short"/>
</composite-id>
........
</class>
This table generates classes Promotion, AbstractPromotion and PromotionKey(this encapsulates the composite PK)

The 2nd table:
<class name="QaNotice" table="qa_notice">
<id name="qaSeq" column="qa_seq" type="java.lang.Integer">
<generator class="assigned"/>
</id>
.....
<many-to-one name="promotion" column="promo_id" class="Promotion" />
<many-to-one name="promotion1" column="sub_promo_id" class="Promotion" />
<many-to-one name="usr" column="user_id" class="java.lang.Integer" not-null="true" />
</class>

generates 2 instances of Promotion in the QANotice class to reference the PK of the same object.
The exception is: Foreign key (qa_notice [promo_id])) must have same number of columns as the referenced primary key (promotion [promo_id,sub_promo_id])
It seems to be the bug that you mentioned already. What can I do to fix it?
Thanks a lot!
 
 View user's profile Send private message  
Reply with quote Back to top
alavoor
Post subject:   PostPosted: Feb 16, 2005 - 05:29 PM
Registered Member
Registered Member


Joined: Jan 11, 2005
Posts: 2

I am facing the same problem.
How to fix this problem??
 
 View user's profile Send private message  
Reply with quote Back to top
avajrd
Post subject:   PostPosted: Mar 24, 2005 - 01:57 AM
Veteran Member
Veteran Member


Joined: Jul 31, 2003
Posts: 13

I'm chiming in with a "me too"
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
avajrd
Post subject:   PostPosted: Mar 24, 2005 - 02:23 AM
Veteran Member
Veteran Member


Joined: Jul 31, 2003
Posts: 13

OK, I admit I'm new to Hibernate, but I found a way around the problem that is described by dianellanunez above.

Change this definition in the 2nd table hbm.xml file to:

The 2nd table:
<class name="QaNotice" table="qa_notice">
<id name="qaSeq" column="qa_seq" type="java.lang.Integer">
<generator class="assigned"/>
</id>
.....
<many-to-one name="promotion" class="Promotion">
<column name="promo_id">
<column namne="sub_promo_id">
</many-to-one>
<many-to-one name="usr" column="user_id" class="java.lang.Integer" not-null="true" />
</class>


That seemed to get me around my problem of the program blowing up during the "processing one-to-many association mappings" step of configuration. I'm not sure if there are other ramifications yet because my test program is not actually referencing this table yet.

Moderator, shouldn't the DB Explorer be creating this sort of mapping?

BTW, I'm using 8.3.4.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
support-jeff
Post subject:   PostPosted: Mar 24, 2005 - 03:30 AM
Moderator
Moderator


Joined: Jul 18, 2004
Posts: 357

Good catch. That is definitely a bug. We are working on some massive re-tooling of the hibernate support now, and I will add this to the list of issues to address.

_________________
jeff
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
avajrd
Post subject:   PostPosted: Mar 24, 2005 - 06:43 PM
Veteran Member
Veteran Member


Joined: Jul 31, 2003
Posts: 13

Cool. Would this be part of the 4.0 Beta?

I have an old application that I did a "role your own" ORM several years ago. I've been wanting to look at hibernate so I ran the DB Explorer hibernate mapping tool on the tables in the database. I found several instances like the one above and a different one. Looks something like this:

CREATE TABLE RISK_ASSESSMENT (
SOFTWARE_BUILD VARCHAR2(25 byte) NOT NULL,
RISK_ASSESSMENT VARCHAR2(4000 byte),
PLAN_NAME VARCHAR2(100 byte) NOT NULL,
PLAN_TYPE VARCHAR2(12 byte),
MODIFIED_BY VARCHAR2(15 byte),
MODIFIED_ON DATE,
CONSTRAINT RISK_ASSESSMENT_PK PRIMARY KEY(PLAN_NAME, SOFTWARE_BUILD)
CONSTRAINT RISK_ASSESSMENT_FK FOREIGN KEY(PLAN_NAME, PLAN_TYPE)
REFERENCES TEST_PLANS(NAME, PLAN_TYPE)
)

generates:

<hibernate-mapping package="com.web.hibernate">

<class name="RiskAssessments" table="RISK_ASSESSMENTS">
<composite-id name="id" class="RiskAssessmentsKey">
<key-many-to-one name="testPlans" column="PLAN_NAME" class="TestPlans"/>
<key-property name="softwareBuild" column="SOFTWARE_BUILD" type="java.lang.String"/>
</composite-id>

<property name="riskAssessment" column="RISK_ASSESSMENT" type="java.lang.String" />
<property name="modifiedBy" column="MODIFIED_BY" type="java.lang.String" />
<property name="modifiedOn" column="MODIFIED_ON" type="java.util.Date" />

<many-to-one name="testPlans1" column="PLAN_TYPE" class="TestPlans" />
</class>

</hibernate-mapping>

This causes the "must have same number of columns " error during the foreign key processing of Configuration.
I have found that the below removes the errors

<hibernate-mapping package="com.web.hibernate">
<class name="RiskAssessments" table="RISK_ASSESSMENTS">
<composite-id name="id" class="RiskAssessmentsKey">
<key-many-to-one name="testPlans" class="TestPlans">
<column name="PLAN_NAME"/>
<column name="PLAN_PLAN_TYPE"/>
</key-many-to-one>
<key-property name="softwareBuild" column="SOFTWARE_BUILD" type="java.lang.String"/>
</composite-id>

<property name="riskAssessment" column="RISK_ASSESSMENT" type="java.lang.String" />
<property name="modifiedBy" column="MODIFIED_BY" type="java.lang.String" />
<property name="modifiedOn" column="MODIFIED_ON" type="java.util.Date" />

<many-to-one name="testPlans" class="TestPlans">
<column name="PLAN_NAME"/>
<column name="PLAN_PLAN_TYPE"/>
</many-to-one>
</class>
</hibernate-mapping>

This could be caused by a poor scheme definition in that the primary key does not include PLAN_TYPE.

I have also seen problems with with composite keys:

<hibernate-mapping package="com.web.hibernate">

<class name="FilterPlan" table="FILTER_PLAN">
<composite-id name="id" class="FilterPlanKey">
<key-many-to-one name="filter" column="FILTER_ID" class="Filter"/>
<key-many-to-one name="testPlans" column="PLAN_NAME" class="TestPlans"/>
<key-many-to-one name="testPlans1" column="PLAN_TYPE" class="TestPlans"/>
<key-many-to-one name="testStrategies" column="STRAT_NAME" class="TestStrategies"/>
</composite-id>

<property name="modifiedBy" column="MODIFIED_BY" type="java.lang.String" />
<property name="modifiedOn" column="MODIFIED_ON" type="java.util.Date" />
</class>

</hibernate-mapping>

This is fixed by:

<hibernate-mapping package="com.web.hibernate">

<class name="FilterPlan" table="FILTER_PLAN">
<composite-id name="id" class="FilterPlanKey">
<key-many-to-one name="filter" column="FILTER_ID" class="Filter"/>
<key-many-to-one name="testPlans" class="TestPlans">
<column name="PLAN_NAME"/>
<column name="PLAN_PLAN_TYPE"/>
</key-many-to-one>
<key-many-to-one name="testStrategies" column="STRAT_NAME" class="TestStrategies"/>
</composite-id>

<property name="modifiedBy" column="MODIFIED_BY" type="java.lang.String" />
<property name="modifiedOn" column="MODIFIED_ON" type="java.util.Date" />
</class>

</hibernate-mapping>

Just wanted to add a few more of my findings.

Thanks, Mike
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits