Hi I am Please help me in this issue
the problem is i cant able to insert the values into the child table here
contact_method is parent table and
contact_relation ship is child table
The bellow is the query for creating the table
the hibernate mapping is also provided so please... help in this issue
The following are the create statements used to design the table in MySql database.
contact_relationship Table:
DROP TABLE IF EXISTS `testing`.`contact_relationship`;
CREATE TABLE `testing`.`contact_relationship` (
`Contact_id` int(10) unsigned NOT NULL,
`Contact_method` int(10) unsigned NOT NULL,
`Person_id` int(10) unsigned default NULL,
`Party_id` int(10) unsigned default NULL,
PRIMARY KEY (`Contact_id`,`Contact_method`),
KEY `FK_contact_relationship_1` (`Contact_method`),
KEY `FK_contact_relationship_2` (`Party_id`,`Contact_id`),
KEY `FK_contact_relationship_4` (`Person_id`,`Contact_method`),
KEY `FK_contact_relationship_5` (`Person_id`,`Contact_id`),
CONSTRAINT `FK_contact_relationship_1` FOREIGN KEY (`Contact_method`) REFERENCES `contact_type` (`Contact_Method`),
CONSTRAINT `FK_contact_relationship_2` FOREIGN KEY (`Party_id`, `Contact_id`) REFERENCES `party_contact` (`Party_id`, `Contact_id`),
CONSTRAINT `FK_contact_relationship_5` FOREIGN KEY (`Person_id`, `Contact_id`) REFERENCES `person_contact` (`Person_id`, `Contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Contact_type Table
DROP TABLE IF EXISTS `testing`.`contact_type`;
CREATE TABLE `testing`.`contact_type` (
`Contact_Method` int(10) unsigned NOT NULL default '0',
`Contact_Type` varchar(45) NOT NULL,
PRIMARY KEY (`Contact_Method`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Party_contact Table:
DROP TABLE IF EXISTS `testing`.`party_contact`;
CREATE TABLE `testing`.`party_contact` (
`Party_id` int(10) unsigned zerofill NOT NULL,
`Contact_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`Party_id`,`Contact_id`),
KEY `FK_party_contact_1` USING BTREE (`Contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Person_contact:
DROP TABLE IF EXISTS `testing`.`person_contact`;
CREATE TABLE `testing`.`person_contact` (
`Person_id` int(10) unsigned NOT NULL,
`Contact_id` int(10) unsigned NOT NULL,
PRIMARY KEY USING BTREE (`Person_id`,`Contact_id`),
KEY `FK_person_contact_1` USING BTREE (`Contact_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Parent table xml mapping
-------------------------------
<hibernate-mapping>
<class name="com.hibernate.PersonContactPo" table="PERSON_CONTACT" schema="ODSCUST_OWNER">
<composite-id name="id" class="com.hibernate.PersonContactPoId">
<key-property name="personId" type="big_decimal">
<column name="PERSON_ID" precision="22" scale="0" />
</key-property>
<key-property name="contactId" type="big_decimal">
<column name="CONTACT_ID" precision="22" scale="0" />
</key-property>
</composite-id>
<set name="contactRelationshipPos" inverse="true">
<key>
<column name="PERSON_ID" precision="22" scale="0" />
<column name="CONTACT_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.hibernate.ContactRelationshipPo" />
</set>
</class>
</hibernate-mapping>
Child table xml mapping
----------------------------
<hibernate-mapping>
<class name="com.hibernate.ContactRelationshipPo" table="CONTACT_RELATIONSHIP" schema="ODSCUST_OWNER">
<composite-id name="id" class="com.hibernate.ContactRelationshipPoId">
<key-property name="contactId" type="big_decimal">
<column name="CONTACT_ID" precision="22" scale="0" />
</key-property>
<key-property name="contactMethodId" type="big_decimal">
<column name="CONTACT_METHOD_ID" precision="22" scale="0" />
</key-property>
</composite-id>
<many-to-one name="personContactPo" class="com.hibernate.PersonContactPo" update="false" insert="false" fetch="select">
<column name="PERSON_ID" precision="22" scale="0" />
<column name="CONTACT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="partyContactPo" class="com.rci.pom.hibernate.PartyContactPo" update="false" insert="false" fetch="select">
<column name="PARTY_ID" precision="22" scale="0" />
<column name="CONTACT_ID" precision="22" scale="0" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
_________________ HIBERNATE QUESTIONS
|