Results 1 to 3 of 3
  1. #1
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    7

    Default [/WEB-INF/applicationContext-dao.xml]: Invocation of init method

    I have two related tables:

    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
    )
    Then I do their xml:
    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
    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>
    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])

  2. #2
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    Default

    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
    Java 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
    Java 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

  3. #3
    bbq
    bbq is offline Senior Member
    Join Date
    Jun 2007
    Posts
    132
    Rep Power
    0

    Default

    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

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 01:23 PM
  3. HELP: Method Invocation
    By rjuyal in forum Advanced Java
    Replies: 4
    Last Post: 04-07-2008, 11:07 AM
  4. Applets (init, start, stop, destroy)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-12-2007, 10:57 AM
  5. init() method displaying html
    By reddzer in forum Java Servlet
    Replies: 0
    Last Post: 11-10-2007, 07:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •