Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-12-2007, 02:38 PM
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])
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-12-2007, 04:37 PM
Senior Member
 
Join Date: Jun 2007
Posts: 119
Peter is on a distinguished road
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
Code:
CREATE TABLE `nuser` ( [...] PRIMARY KEY (`notification_id`,`nuser_id`), )
But, here you tell it, to does a reference to a nuser table, only with the column notification_id
Code:
CREATE TABLE `nuseractions` ( CONSTRAINT `nuseractions_fk` FOREIGN KEY (`notification_id`) REFERENCES `nuser` (`notification_id`) ON DELETE CASCADE ON UPDATE CASCADE,
But nuser has a primary key with 2 columns, so it's incorrect.
check it, and fix it
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-12-2007, 05:33 PM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
The problem is your second mapping, you have a relationship many-to-one with "user" but you define a tag "column" when actually must define 2 of the user (you defined a composite-id for this object with 2 columns)

Good luck
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Help pringle New To Java 4 04-16-2008 02:23 PM
HELP: Method Invocation rjuyal Advanced Java 4 04-07-2008 12:07 PM
Applets (init, start, stop, destroy) Java Tip Java Tips 0 12-12-2007 11:57 AM
init() method displaying html reddzer Java Servlet 0 11-10-2007 08:20 PM
method not abstract, does not override actionperformed method. Theman New To Java 1 05-08-2007 07:13 AM


All times are GMT +3. The time now is 09:29 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org