Results 1 to 3 of 3
- 06-12-2007, 01:38 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 164
- Rep Power
- 6
[/WEB-INF/applicationContext-dao.xml]: Invocation of init method
I have two related tables:
Then I do their xml:Java 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 )
First table
Java 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
It works fine, all is defined and valid, but when the beans is configured appears this error:Java 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>
[/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])
- 06-12-2007, 03:37 PM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 119
- Rep Power
- 0
Your problem isn't Hibernate, but the definition of the tables:
Check this:
Here, you define the primary key of the nuser and it is 2 columns
notification_id and nuser_id
But, here you tell it, to does a reference to a nuser table, only with the column notification_idJava Code:CREATE TABLE `nuser` ( [...] PRIMARY KEY (`notification_id`,`nuser_id`), )
But nuser has a primary key with 2 columns, so it's incorrect.Java Code:CREATE TABLE `nuseractions` ( CONSTRAINT `nuseractions_fk` FOREIGN KEY (`notification_id`) REFERENCES `nuser` (`notification_id`) ON DELETE CASCADE ON UPDATE CASCADE,
check it, and fix it
- 06-12-2007, 04:33 PM #3
Senior Member
- Join Date
- Jun 2007
- Posts
- 132
- Rep Power
- 0
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
Method Help
By pringle in forum New To JavaReplies: 4Last Post: 04-16-2008, 01:23 PM -
HELP: Method Invocation
By rjuyal in forum Advanced JavaReplies: 4Last Post: 04-07-2008, 11:07 AM -
Applets (init, start, stop, destroy)
By Java Tip in forum Java TipReplies: 0Last Post: 12-12-2007, 10:57 AM -
init() method displaying html
By reddzer in forum Java ServletReplies: 0Last Post: 11-10-2007, 07:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks