-->
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.  [ 1 post ] 
Author Message
 Post subject: Issue many-to-one relationship with two different references
PostPosted: Fri Dec 07, 2007 4:43 am 
Newbie

Joined: Mon Nov 19, 2007 3:15 am
Posts: 2
Hi,
I'm also facing the issue like that.

Tables created in MySQL:

CREATE TABLE PARTY (
PARTY_ID INTEGER,
PARTY_TYPE VARCHAR(60) NOT NULL,
CONSTRAINT XPKPARTY PRIMARY KEY (PARTY_ID)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE ROLE (
ROLE_ID INTEGER,
ROLE_TYPE VARCHAR(60) NOT NULL,
CONSTRAINT XPKROLE PRIMARY KEY (ROLE_ID)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE PARTY_ROLE (
ROLE_ID INTEGER,
PARTY_ID INTEGER,
CONSTRAINT XPKPARTY_ROLE PRIMARY KEY (ROLE_ID, PARTY_ID),
CONSTRAINT FK_PARTY FOREIGN KEY (PARTY_ID) REFERENCES PARTY (PARTY_ID),
CONSTRAINT FK_ROLE FOREIGN KEY (ROLE_ID) REFERENCES ROLE (ROLE_ID)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE RELATIONSHIP_RESULT (
ROLE_ID_FROM INTEGER,
ROLE_ID_TO INTEGER,
RELATIONSHIP_RESULT VARCHAR(60) NOT NULL,
CONSTRAINT XPKRELATIONSHIP_RESULT PRIMARY KEY (ROLE_ID_FROM, ROLE_ID_TO)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE RELATIONSHIP (
MEMBERSHIP_ID INTEGER,
RL_PARTY_ID_FROM INTEGER NOT NULL,
RL_ROLE_ID_FROM INTEGER NOT NULL,
RL_PARTY_ID_TO INTEGER NOT NULL,
RL_ROLE_ID_TO INTEGER NOT NULL,
CONSTRAINT XPKRELATIONSHIP PRIMARY KEY (MEMBERSHIP_ID),
CONSTRAINT FK_ROLE_FROM FOREIGN KEY (RL_ROLE_ID_FROM, RL_PARTY_ID_FROM) REFERENCES PARTY_ROLE (ROLE_ID, PARTY_ID),
CONSTRAINT FK_ROLE_TO FOREIGN KEY (RL_ROLE_ID_TO, RL_PARTY_ID_TO) REFERENCES PARTY_ROLE (ROLE_ID, PARTY_ID),
CONSTRAINT FK_RELN_RESULT FOREIGN KEY (RL_ROLE_ID_FROM, RL_ROLE_ID_TO) REFERENCES RELATIONSHIP_RESULT (ROLE_ID_FROM, ROLE_ID_TO)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;

Using Hibernate tools to generate the hbm and pojo files.

In Relationship.hbm.xml shows:

<class name="com.cts.dao.pom.Relationship" table="relationship" catalog="test">
<comment></comment>
<id name="membershipId" type="int">
<column name="MEMBERSHIP_ID" />
<generator class="assigned" />
</id>
<many-to-one name="partyRoleByFkRoleTo" class="com.cts.dao.pom.PartyRole" fetch="select">
<column name="ROLE_ID_TO" not-null="true">
<comment></comment>
</column>
<column name="PARTY_ID_TO" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="relationshipResult" class="com.cts.dao.pom.RelationshipResult" update="false" insert="false" fetch="select">
<column name="ROLE_ID_FROM" not-null="true">
<comment></comment>
</column>
<column name="ROLE_ID_TO" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="partyRoleByFkRoleFrom" class="com.cts.dao.pom.PartyRole" update="false" insert="false" fetch="select">
<column name="ROLE_ID_FROM" not-null="true">
<comment></comment>
</column>
<column name="PARTY_ID_FROM" not-null="true">
<comment></comment>
</column>
</many-to-one>
</class>

In the <many-to-one name="partyRoleByFkRoleTo" tag there is no attributes having insert="false" update ="false"

but in the same table the other reference for <many-to-one name="partyRoleByFkRoleFrom tag there it having the attibutes insert="false" update ="false".

We can able to insert partyRoleByFkRoleTo object in to Relationship table but cannot able to insert partyRoleByFkRoleFrom object in to Relationship table. How we insert the both the object in to the Relationship table?


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

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.