Results 1 to 9 of 9

Thread: ROO: how to create composit primary key in Entity

  1. #1
    Join Date
    May 2010
    Posts
    7

    Default ROO: how to create composit primary key in Entity

    Hi,

    What can I do if I need to create entity for
    a table in production DB (Oracle 10g) with composite primary key.

    For example:
    Code:
    CREATE TABLE TACCOUNT
    (
      BRANCHID     NUMBER(3)                        NOT NULL,
      ACC          VARCHAR2(18 BYTE)                NOT NULL,
      DATE_OPEN    DATE                             NOT NULL,
      DATE_CLOSE   DATE,
      NOTE         VARCHAR2(38 BYTE)
    );
    CREATE UNIQUE INDEX PK_TACCOUNT ON TACCOUNT
    (BRANCHID, ACC);
    I don't want to change the structure of this table.

    Is it possible to create an "id" field using roo commands?

    I use Spring Roo 1.0.2.RELEASE [rev 638]

    Paul

  2. #2

    Default

    Hi,

    there seem to be no support for composite primary keys in Roo 1.0.x.

    As you can see in Roo-505 there is some development going on to support composite keys in the future.

    I have created the following example script for the current development build of Roo (not the release version):

    Code:
    // Spring Roo ENGINEERING BUILD [rev unknown] log opened at 2010-05-07 14:48:41
    project --topLevelPackage de.schmidtsoftware.rooquickhacks
    persistence setup --provider HIBERNATE --database MYSQL 
    entity --class de.schmidtsoftware.rooquickhacks.domain.Node --testAutomatically
    field string --fieldName color --notNull 
    entity --class de.schmidtsoftware.rooquickhacks.domain.Edge --identifierType EdgeId --testAutomatically
    field string --fieldName color --notNull
    field reference --fieldName fromNode --type de.schmidtsoftware.rooquickhacks.domain.Node --class de.schmidtsoftware.rooquickhacks.domain.EdgeId
    field reference --fieldName toNode --type de.schmidtsoftware.rooquickhacks.domain.Node --class de.schmidtsoftware.rooquickhacks.domain.EdgeId
    // [failed] controller all --package de.schmidtsoftware.rooquickhacks.web
    perform eclipse
    The script will create a node class (with color field and id field) and an edge class (with color field and composite id field [fromNode, toNode]). This works fine for me, Java and ITD files look good. The tables as well, as you can see in the screenshot.



    Nevertheless there seem to be some problems with the generated integration tests. Furthermore, I was not able to create the web controllers for this project. I guess either you, me or somebody else need to have a closer look on that, but it should be a good starting point for you.
    Attached Images Attached Images

  3. #3

    Default

    Anyone has resolved this issue in Roo 1.1.4 i am using roo for a big project where there is a lot of primary keys and foreign one involved .?
    any commands that can be used for that ? I have tried the @Id it doesn't work .

  4. #4
    Join Date
    Dec 2005
    Posts
    930

    Default

    Composite keys are supported in 1.1.x. Use for example:
    Code:
    entity --class ~.domain.Foo --identifierType ~.domain.FooPK
    Then add fields to the composite key class using the field command as normal
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  5. #5

    Default

    thanks for your help

  6. #6
    Join Date
    Jun 2011
    Posts
    2

    Default

    about fields in composite key class, they have to be NOT NULL ?
    or fields just only refer to other class without any specifications ?

  7. #7
    Join Date
    Dec 2005
    Posts
    930

    Default

    From a data modelling perspective, a composite key would always be not null. This is from 15 years of Oracle and DB2 experience
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  8. #8
    Join Date
    Aug 2011
    Location
    Santiago, Chile
    Posts
    20

    Default

    I'm using key composite too and DBRE, everything works fine but when I put the option "show example" I get the following error:

    "No Example found with this id."
    and the row exists with this id.

  9. #9
    Join Date
    Aug 2011
    Location
    Santiago, Chile
    Posts
    20

    Unhappy

    Really do not understand the problem.

    I need help. please.

Tags for this Thread

Posting Permissions

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