facebook

Foreign key must have same number of columns

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #299553 Reply

    tatavarthi
    Member

    Hello,

    I am trying to use JPA reverse engineering on two tables: ASSIGNMENT and ACTUAL.

    ASSIGNMENT table has a composite key and ACTUAL key has a foriegn key to the ID column of the ACTUAL table.

    
    =========
    CREATE TABLE [dbo].[ASSIGNMENT](
        [ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
        [PROJECT_ID] [numeric](18, 0) NOT NULL,
        [TASK_ID] [numeric](18, 0) NOT NULL,
        [RESOURCE_ID] [numeric](18, 0) NOT NULL,
        [COST] [numeric](18, 0) NULL,
        [HOURS] [numeric](18, 0) NULL,
        [RATE] [numeric](18, 0) NULL,
        [ROLE_ID] [numeric](18, 0) NULL,
        [STATUS] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
        [DEFERRED] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
        [DEFERRED_TO_QTR] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
     CONSTRAINT [PK_ASSIGNMENT] PRIMARY KEY CLUSTERED 
    (
        [PROJECT_ID] ASC,
        [TASK_ID] ASC,
        [RESOURCE_ID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    SET ANSI_PADDING OFF
    GO
    ALTER TABLE [dbo].[ASSIGNMENT]  WITH CHECK ADD  CONSTRAINT [FK_ASSIGNMENT_RESOURCE] FOREIGN KEY([RESOURCE_ID])
    REFERENCES [dbo].[RESOURCE] ([ID])
    GO
    ALTER TABLE [dbo].[ASSIGNMENT] CHECK CONSTRAINT [FK_ASSIGNMENT_RESOURCE]
    GO
    ALTER TABLE [dbo].[ASSIGNMENT]  WITH CHECK ADD  CONSTRAINT [FK_ASSIGNMENT_ROLE] FOREIGN KEY([ROLE_ID])
    REFERENCES [dbo].[ROLE] ([ID])
    GO
    ALTER TABLE [dbo].[ASSIGNMENT] CHECK CONSTRAINT [FK_ASSIGNMENT_ROLE]
    GO
    ALTER TABLE [dbo].[ASSIGNMENT]  WITH CHECK ADD  CONSTRAINT [FK_ASSIGNMENT_TASK] FOREIGN KEY([TASK_ID])
    REFERENCES [dbo].[TASK] ([ID])
    GO
    ALTER TABLE [dbo].[ASSIGNMENT] CHECK CONSTRAINT [FK_ASSIGNMENT_TASK]
    GO
    ALTER TABLE [dbo].[ASSIGNMENT]  WITH CHECK ADD  CONSTRAINT [FK_PROJECT_ASSIGNMENT] FOREIGN KEY([PROJECT_ID])
    REFERENCES [dbo].[PROJECT] ([ID])
    GO
    ALTER TABLE [dbo].[ASSIGNMENT] CHECK CONSTRAINT [FK_PROJECT_ASSIGNMENT]
    
    =======
    
    CREATE TABLE [dbo].[ACTUAL](
        [ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
        [ASSIGNMENT_ID] [numeric](18, 0) NOT NULL,
        [DATE] [datetime] NULL,
        [HOURS] [numeric](18, 0) NULL,
        [INVOICED] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
        [ORACLE_INVOICE_NUMBER] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
        [PM_APPROVED] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
        [NOTES] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
     CONSTRAINT [PK_ACTUAL] PRIMARY KEY CLUSTERED 
    (
        [ID] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    SET ANSI_PADDING OFF
    GO
    ALTER TABLE [dbo].[ACTUAL]  WITH CHECK ADD  CONSTRAINT [FK_ACTUAL_ASSIGNMENT] FOREIGN KEY([ASSIGNMENT_ID])
    REFERENCES [dbo].[ASSIGNMENT] ([ID])
    GO
    ALTER TABLE [dbo].[ACTUAL] CHECK CONSTRAINT [FK_ACTUAL_ASSIGNMENT]
    
    

    When I try to reverse engineer, I get the following error:

    An internal error occurred during: "Generating Artifacts".
    Foreign key (FK72C29D8E68BF10A8:ACTUAL [ASSIGNMENT_ID])) must have same number of columns as the referenced primary key (ASSIGNMENT [PROJECT_ID,TASK_ID,RESOURCE_ID])

    I saw other posts that report the same error, but I did not find any resolution. Does the reverse egineering support composite keys? I would appreciate your guidance.

    Thanks!
    Sreedhar

    #299672 Reply

    Loyal Water
    Member

    Sreedhar,
    Im not sure what could be causing the problem here. May some other users on the forum could help you with this. I would suggest you cross post this query on the JPA forums as well.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Foreign key must have same number of columns

You must be logged in to post in the forum log in