View Single Post
  #1 (permalink)  
Old 06-12-2007, 02:38 PM
Heather Heather is offline
Senior Member
 
Join Date: Jun 2007
Posts: 164
Heather is on a distinguished road
[/WEB-INF/applicationContext-dao.xml]: Invocation of init method
I have two related tables:

Code:
CREATE TABLE `nuser` ( `notification_id` bigint(20) NOT NULL, `nuser_id` varchar(255) NOT NULL, `nuser_startdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `nuser_enddate` timestamp NOT NULL default '0000-00-00 00:00:00', `nuser_isprivate` bit(1) NOT NULL, `nuser_isowner` bit(1) NOT NULL, `nuser_state` varchar(255) NOT NULL default 'nv', PRIMARY KEY (`notification_id`,`nuser_id`), KEY `notification_id` (`notification_id`), KEY `nuser_id` (`nuser_id`), CONSTRAINT `nuser_ibfk_1` FOREIGN KEY (`notification_id`) REFERENCES `notification` (`notification_id`) ON DELETE CASCADE ON UPDATE CASCADE ) CREATE TABLE `nuseractions` ( `nuseractions_id` bigint(20) NOT NULL auto_increment, `notification_id` bigint(20) NOT NULL, `nuser_id` varchar(255) NOT NULL, `nuseractions_state` varchar(255) NOT NULL, `nuseractions_date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`nuseractions_id`), KEY `notification_id` (`notification_id`), KEY `nuser_id` (`nuser_id`), CONSTRAINT `nuseractions_fk` FOREIGN KEY (`notification_id`) REFERENCES `nuser` (`notification_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `nuseractions_ibfk_2` FOREIGN KEY (`nuser_id`) REFERENCES `nuser` (`nuser_id`) ON DELETE CASCADE ON UPDATE CASCADE )
Then I do their xml:
First table


Code:
<composite-id name="id" class="com.bs.proteo.notifications.bl.beans.NuserId"> <key-property name="notificationId" type="long"> <column name="notification_id" /> </key-property> <key-property name="nuserId" type="string"> <column name="nuser_id" /> </key-property> </composite-id> <many-to-one name="notification" class="com.bs.proteo.notifications.bl.beans.Notification" update="false" insert="false" fetch="select"> <column name="notification_id" not-null="true"> <comment></comment> </column> </many-to-one> <property name="nuserStartdate" type="timestamp"> <column name="nuser_startdate" length="19" not-null="true"> <comment></comment> </column> </property> <property name="nuserEnddate" type="timestamp"> <column name="nuser_enddate" length="19" not-null="true"> <comment></comment> </column> </property> <property name="nuserIsprivate" type="serializable"> <column name="nuser_isprivate" not-null="true"> <comment></comment> </column> </property> <property name="nuserIsowner" type="serializable"> <column name="nuser_isowner" not-null="true"> <comment></comment> </column> </property> <property name="nuserState" type="string"> <column name="nuser_state" not-null="true"> <comment></comment> </column> </property> <map name="nuseractionsesForNotificationId" inverse="true"> <key> <column name="notification_id" not-null="true"/> </key> <map-key type="long" column="notification_id"/> <one-to-many class="com.bs.proteo.notifications.bl.beans.Nuseractions" /> </map> <map name="nuseractionsesForNuserId" inverse="true"> <key> <column name="nuser_id" not-null="true"/> </key> <map-key type="long" column="nuser_id"/> <one-to-many class="com.bs.proteo.notifications.bl.beans.Nuseractions" /> </map>


Second table
Code:
<comment></comment> <id name="nuseractionsId" type="long"> <column name="nuseractions_id" /> <generator class="assigned" /> </id> <!-- many-to-one name="notification" class="com.bs.proteo.notifications.bl.beans.Notification" fetch="select"> <column name="notification_id" not-null="true"> <comment></comment> </column> </many-to-one> <many-to-one name="nuser" class="com.bs.proteo.notifications.bl.beans.Nuser" fetch="select"> <column name="nuser_id" not-null="true"> <comment></comment> </column> </many-to-one --> <property name="nuseractionsState" type="string"> <column name="nuseractions_state" not-null="true"> <comment></comment> </column> </property> <property name="nuseractionsDate" type="timestamp"> <column name="nuseractions_date" length="19" not-null="true"> <comment></comment> </column> </property>
It works fine, all is defined and valid, but when the beans is configured appears this error:

[/WEB-INF/applicationContext-dao.xml]: Invocation of init method
failed; nested exception is org.hibernate.MappingException: Foreign
key (FK93DEA1A49CE1EDAC:nuseractions [notification_id])) must have
same number of columns as the referenced primary key (nuser
[notification_id,nuser_id])
Reply With Quote
Sponsored Links