Use multiple primary keys to create DB constraint

Hi,
Is it possible to have multiple primary keys within one EJB to create a DB including the constraints, if so how? Is there an example of this or any example which uses multiple primary keys to create a DB?
Thanks,
Maarten

"Is it possible to have multiple primary keys within one EJB..."
If you mean a composite key, yes. Your PrimaryKeyObject would have one attribute for each column that makes up your composite key. If that's not what you meant, please clarify.
"...to create a DB including the constraints"
Not sure what you mean here. Constraints are enforced by the DB, and you don't create databases with EntityBeans.

Similar Messages

  • Multiple Primary Keys - MySQL to Oracle 9i

    I was wondering, does OMWB make the necessary sequences and triggers in the database migration in which a table in MySQL has multiple primary keys. Based on my migration, I took at look at then Enterprise Manager, all i saw was that a squence was created but it did not say which column.
    Could someone give me any advice on this, this is the first time using this.
    Tks,
    Andrew

    Andrew,
    only one PRIMARY KEY can exist on a table - you can have multiple UNIQUE indexes. OMWB migrates each PRIMARY KEY and
    UNIQUE index in MySQL to PRIMARY KEY and UNIQUE indexes in Oracle. This is why I am not clear about your question. You would
    see TRIGGERS and SEQUENCES created by OMWB when it migrates the ENUM and AUTO INCREMENT. Can you explain
    the problems you are having a little more please? I hope the information I have already provided is of some help.
    Regards,
    Team OMWB.

  • How shall we do validation for Unique Key and Multiple Primary Key?

    Hi,
    I have table created From EO in which one column is checked as Unique.
    How to do validation for column checked as Unique.
    I know how to do validation for column checked as primary key.
    Below is sample code for primary key validation
    if (getRvSize() != null)
    throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
    getEntityDef().getFullName(), // EO name
    getPrimaryKey(), // EO PK
    "RvSize", // Attribute Name
    value, // Attribute value
    "AK", // Message product short name
    "FWK_TBX_T_EMP_ID_NO_UPDATE"); // Message name
    if (value != null)
    OADBTransaction transaction = getOADBTransaction();
    Object[] rvKey = {value};
    EntityDefImpl rvDefinition = xxczVAGCSRVSizingEOImpl.getDefinitionObject();
    xxczVAGCSRVSizingEOImpl rv =
    (xxczVAGCSRVSizingEOImpl)rvDefinition.findByPrimaryKey(transaction, new Key(rvKey));
    if (rv != null)
    throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
    getEntityDef().getFullName(), // EO name
    getPrimaryKey(), // EO PK
    "RvSize", // Attribute Name
    value, // Attribute value
    "AK", // Message product short name
    "FWK_TBX_T_EMP_ID_UNIQUE"); // Message name
    What changes need to be done for above code in order to do the validation for Unique Key.
    I have one more Question
    How shall we do the Validation for Multiple Primary Key in a table?
    - Mithun

    1. If you just validate on one attribute like your unique key, then put your logic in the set<Your AttributeName) method
    2. If you want to do the cross validation ( like validating multiple attributes) then put your logic in the validateEntrity Method
    How to do that?
    1. Create a Validation View object.
    2. Associate your VVO to the VAM
    3. Create entity expert.
    4. Have method in entity expert for your validation (you would be calling AM and then VO execute the query and do the validation.
    5. You would be calling the Entity experty method from your EO either setMethods or validateEntity.
    I have given just the high level points.
    Hope this helps.
    Thanks,
    RK

  • Updating Primary key while creating entries

    Hi All,
    I have a requirement to update a primary key while the entry is being created in the database table.
    The program uses the INSERT statement to create entries but the primary key is unknown at that time. I want to create this primary key value and update that record before being saved in the database.
    Is there a place where i can write this code which gets called while INSERT/UPDATE statements.
    Request you urgent help.
    Thanks in advance

    Hello Archana,
    As per my understanding providing BADI implementation is one of the better options you have.
    Firstly you have to find out the standard BADI Definition provided by SAP for your functionality. You can search the same in the transaction <b>SE18</b>.
    Your BADI definition will have predefined interface methods
    (like BEFORE_SAVE, AFTER_SAVE, BEFORE_UPDATE, AFTER_UPDATE ... )
    with necessary parameters(parameter types: IMPORTING/EXPORTING/CHANGING/RETURNING). Mind you, you can't add your own methods/parameters to these standard BADI definitions.
    Now you can create your own BADI implementation(ie., you can write you code in the one of the predefined methods you have) for the standard BADI definition. For that in your BADI Definition screen go to <i>Implementation</i> in Menu bar and click on <i>Create</i>.
    I hope you will definitely have <b>Primary Key</b> as importing parameter so you can write your code logic by using this primary key in one of the methods you have based on your requirement
    <b>@</b> Please take Backend expert help in your team for finding out BADI Definition Name & for also BADI Implementation Code if you are not sure about BADI concept.
    I hope this answers your question, If YES,  !!! REWARD POINTS !!!
    Regards, Srikanth

  • Having a problem with creating/using a primary key on a view

    I have a problem with a primary key on a view
    I created the view and primary key as follows:
    CREATE OR REPLACE FORCE VIEW "MDD"."ROCK_LU" ("DESCRIPTION",
         UNIQUE ("DESCRIPTION") RELY DISABLE,
         CONSTRAINT "ROCK_LU_PK" PRIMARY KEY ("DESCRIPTION") RELY DISABLE) AS
    SELECT DESCRIPTION
    FROM MRMC_LU
    WHERE ROCK = 'T';
    The view with the primary key appears to have been created as there were no error messages. (The above was from the sql tab in sql developer.)
    When I try to create the foreign key on my mdd_hr table - I get an error
    /* hr_name - foreign key */
    ALTER TABLE mdd_hr add CONSTRAINT hr_name_fk FOREIGN KEY (hr_name) REFERENCES rock_lu(description);
    Error report:
    SQL Error: ORA-02270: no matching unique or primary key for this column-list.
    When I lookup the index in sql developer, rock_lu_pk is not there.
    All my other foreign keys work - but I don't understand what I am doing wrong with this one. Please help.
    glenn
    Background - as to why I want to use a view as a lookup table.
    The MRMC_LU table that the view is created from is structured like:
    DESCRIPTION - MINERAL - ROCK - MODIFIER - COMMODITY
    ANHYDRITE - T - T - T
    APLITE - T - - T
    GRAPHITE - T - - - T
    GREYWACKE - - T
    DESCRIPTION is a list of all names of minerals, rocks, modifiers and commodities. T is entered in each valid field. Often a description name is used for both a mineral and a rock or a mineral and a commodity or any other combination. Because this database is just starting up, it was more efficient to create one table that could be updated (and thereby automatically update the MINERAL_LU, ROCK_LU, MODIFIER_LY, COMMODITY_LU views) rather than create and maintain four separate but similar tables. A primary key cannot be generated for the MRMC_LU table as there are nulls in each column
    except DESCRIPTION.
    Perhaps there is a smarter way to do this?

    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_85a.htm#2065512
    You can specify constraints on views and object views. You define the constraint at the view level using the out_of_line_constraint clause. You define the constraint as part of column or attribute specification using the inline_constraint clause after the appropriate alias.
    Oracle does not enforce view constraints. However, operations on views are subject to the integrity constraints defined on the underlying base tables. This means that you can enforce constraints on views through constraints on base tables.
    Restrictions on View Constraints
    View constraints are a subset of table constraints and are subject to the following restrictions:
    You can specify only unique, primary key, and foreign key constraints on views. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.
    Because view constraints are not enforced directly, you cannot specify INITIALLY DEFERRED or DEFERRABLE.
    View constraints are supported only in DISABLE NOVALIDATE mode. You must specify the keywords DISABLE NOVALIDATE when you declare the view constraint, and you cannot specify any other mode.
    You cannot specify the using_index_clause, the exceptions_clause clause, or the ON DELETE clause of the references_clause.
    You cannot define view constraints on attributes of an object column.
    Rgds.

  • I am trying to create a sequence to be use as primary key in a Oracle table

    Hi guys
    I have the ODI version 10.3.5 and I am trying to create a sequence that populates de row_id for a table. The schema is a database.
    And I want that this item will be the primary key of the table that is loaded at execute the interface however I'm getting issues.
    So please advise me.

    Hi ,
    Can you please provide the following details :
    1. What is the execution area of your sequence ? Is it source or staging or Target.
    2. What IKM you are using ( I hope you are executing sequence in Staging or Target ) ?
    My understanding is when you check Not Null , all your rows are going to Error table. So it is not giving any error.
    When you uncheck the Not Null , it is giving error because Database is not allowing Null values in the Primary Key Column.
    You can do the following to check if your sequence is working properly.
    Try to write a Insert Select query in DB and execute it and see if it is working properly.
    i.e.
    insert into      EMPL     (
         EMPNO,
         ENAME,
         JOB,
         MGR,
         HIREDATE,
         SAL,
         COMM,
         DEPTNO
    select      S_EMPNO.NEXTVAL,
         ENAME,
         JOB,
         MGR,
         HIREDATE,
         SAL,
         COMM,
         DEPTNO
    from     EMP
    or if you can provide your query in this format , it will help in finding the issue quickly.Also provide the KM details.

  • Error with Links if using x3 primary keys

    Hi Folks:
    Here is the error code I'm receiving:
    ORA-01422: exact fetch returns more than requested number of rows
    Unable to fetch row.
    Background: I am using Application Express 3.2
    All of the pages I have created that rely on x2 primary keys (first_name, last_name) work fine.
    I have a table that has x3 primary keys: Table is called "time_off_awards". The x3 primary keys are: last_name, first_name, approval_date.
    I created a report that works properly and lists the awards for each person (each person can receive more than one award-on different dates).
    I also created an edit link that works properly IF *(only if)* each individual has only one award. If the individual has more than one award then I get the error above. When I set up the link I used all three keys. The x3 PK's should uniquely identify each row, but if the same last name/first name appear more than once (that is if the person has more than one award) I get the error. I thought at first maybe it was just not reading the 3rd key/part of the link (approval_date), but it shows properly if you move your cursor over the edit link.
    Here is a link to a screen pic of how I have my link set in Apex:
    [http://www.wczone.com/link_settings.gif]
    Here is a link to a pic of the report with some info:
    [http://www.wczone.com/report_link.gif]
    If needed, here is my table info:
    CREATE TABLE PERSONNEL.TIME_OFF_AWARDS (
    LAST_NAME VARCHAR2(40) NOT NULL,
    FIRST_NAME VARCHAR2(25) NOT NULL,
    APPROVAL_DATE DATE NOT NULL,
    HOURS_OFF NUMBER(3),
    CITATION VARCHAR2(1500),
    /* Keys */
    PRIMARY KEY (LAST_NAME, FIRST_NAME, APPROVAL_DATE),
    /* Foreign keys */
    CONSTRAINT TOA_PERSONNEL
    FOREIGN KEY (LAST_NAME, FIRST_NAME)
    REFERENCES PERSONNEL.MARC_PERSONNEL(LAST_NAME, FIRST_NAME)
    TABLESPACE PERSONNEL;
    Thanks for any help, I've tried looking at a couple of Apex books, but they didn't help much.
    Matt
    Edited by: user10495310 on Mar 4, 2009 8:21 AM

    Thank you everyone for the help and information you gave to me.
    Your ideas and advice helped me to think through the issues involved.
    The way i actually found to work around this issue was a little different.
    What I did was the following (which may only be usable with empty tables. If its possible to create a new column with a sequence and trigger on a table that already contains data it should work also):
    1. I removed the current PK's that were currently set.
    2. I added a single, unique PK (that used a sequence and trigger to automatically increment) to the table as was suggested in this thread and other APEX forum threads.
    3. I changed the link on the report so that it used the new PK, and also changed the PK used on the forms (under Processes - both the page rendering and page processing processes).
    The Difference:
    4. Next I changed the table (not by using APEX, but directly) from using the automatically generated ID as the PK, back to using the compound PK (x3 keys). I then added an constraint to make sure that the automatically generated column was unique. So now I have the compound PK that my supervisor wants us to use, and I'm able to use a unique, automatically generated key for APEX to use.
    I found also that if you already have a column that uses a unique/auto-generated key you can still use it with APEX without switching keys around.
    1. I added the new column to the sql in the reports source section so that the new column was searched (and then used 'hidden' so it wouldn't be displayed on the report users would see).
    2. You can still add the unique key under the processes on the form that is being linked too under the Primary key tabs. If its not a PK it won't show up in the pop up which is to the right of "Item Containing Primary Key Column Value" but it can be entered manually (i.e. p23_AUTO_ID) and it will work fine. You would also need to edit your form so that the auto ID that is being passed from the report is part of the form - but hidden if desired).

  • Primary Key in Create as Select

    In Oracle, how do we specify a primary key in a create as select statement? I ran a simple statement but received the ORA-00933 error. Do I have to make it two steps with table created first and do alter table to add the key?
    Thanks,
    CREATE TABLE Test as
    SELECT
    FROM Source a
    WHERE a.sys=100
    CONSTRAINT PK1 PRIMARY KEY (AccountID)

    Do I have to make it two steps with table created first and do alter table to add the key? Only if you wish to use the * notation. If you're prepared to specify the columns you can do it in a single step.
    SQL> create table my_emp
      2      (empno constraint myemp_pk primary key
      3      , ename
      4      , sal)
      5  as select empno
      6      , ename
      7      , sal
      8  from
      9  emp
    10  /
    Table created.
    SQL> select * from my_emp
      2  /
         EMPNO ENAME             SAL
          7369 CLARKE            800
          7499 VAN WIJK         1600
          7521 PADFIELD         1250
          7566 ROBERTSON        2975
          7654 BILLINGTON       1250
          7698 SPENCER          2850
          7782 BOEHMER          2450
          7788 RIGBY            3000
          7839 SCHNEIDER        5000
          7844 CAVE             1500
          7876 KULASH           1100
          7900 HALL              950
          7902 GASPAROTTO       3000
          7934 KISHORE          1300
    14 rows selected.
    SQL>Cheers, APC
    blog: http://radiofreetooting.blogspot.com
    Edited by: APC on Apr 9, 2009 1:55 PM
    Forgot to include the CTAS statement. Doh!

  • Problem with a primary key when creating a new record in Forms

    My table has a field - MDD_KEY - that is a primary key. It is updated from a sequence with a before-insert database trigger. I know this works properly as the primary key was accurately populated when I inserted 1433 records.
    In Forms 6, I have a form based on that table. I have set the mdd_key as a hidden field because I assume it will be entered by the before-insert trigger. However, when I enter data into the table, and then try to save it, I get a FRM-40202: Field must be entered. - followed by - FRM-40222: Disabled item MDD_KEY failed validation.
    If I set DATA Required to no, when I try to save I get an FRM-40600: Record has already been inserted - but no such record exists in the database. I know this record is unique and does NOT exist because I deliberately made it up.
    In the property palatte, the attributes of the field are:
    DATA Data Type Number
    Required Yes
    DATABASE Database Item Yes
    Primary Key Yes
    Query Only No
    Query Allowed Yes
    Query Length 0
    Insert Allowed Yes
    Update Allowed Yes
    Update Only if Null No
    Lock Record No
    I assume that my problem is that with a new record, the form wants to see the MDD_KEY populated before it saves - but that isn't going to happen until the before insert trigger fires in the database. I assume I have to populate that field within forms, but how do I do that without messing up the database trigger/sequence? I will have to load more data directly into the database - so I need the database trigger in place.
    I have not used primary keys before so I am more than a little bit confused about how and when it should be populated when a new record is created in Forms.
    Any help would be appreciated as I cannot enter new data into my form (works well with existing data).
    Thanks
    Glenn

    hi
    if u have any problem using seq then try that statemetn ur block level in ur form
    PRE-INSERT trigger
    select nvl(max(nvl(srno,0)),0)+1 into :srno from tablename;
    Rizwan

  • Use of primary key

    hi guru
    without using primary key, is this possible to create table.
    regards
    subhasis.

    hi,
    I will explain with simple example.
    suppose there is table storing passport number and name of employye.
    so the developer created a table with these two fields, and there is no primary key in that.
    so when inserting data, any 1 can insert any data with duplicates value.. just imagina situation where two people has same passport number, due to this bad data base design.
    so the solution is to avoid duplicate entries, for that we haev to cmake passport number as primary key.it will vaoid duplicate entries.
    hipe u undrstud.
    Rgds
    Anversha

  • Primary key when creating reports with forms

    I'm new to APEX and I'm creating a report with forms using the wizard. I've checked the 'Include Analysis Pages' checkbox. When I select the 'add pages' button I get the following message:
    Table has no primary keys defined. A primary key is required when creating reports with forms.
    I know that the table does have a primary key because I defined it and also it is visible in the Sql workshop / Object browser and Toad.
    Am I missing something or is this some sort of bug?
    thanks
    sb

    You're missing something. This message means you've not told APEX what the primary key is. You shouldn't have been able to get passed the page in the wizard that asks for it though. Can't describe where it prompts for it from memory, but it shouldn't be hard to find.
    HTH
    Chris.

  • Using a uddi key to create a business service in OSB

    I want to be able to use a service registry key when creating a business service in OSB. I've found documentation on how to do this in Oracle ESB, but not in OSB.
    From the documentation for OSB, I can only find a way to synchronize the business services imported from the service registry (when i search through the imported services there is no mention of the uddi key that i can see). I can choose to auto-import when setting up the registry, but I'm not sure exactly what this behavior does.
    From the console documentation (http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/consolehelp/uddi.html)
    "You can use the Auto-Import Status page to synchronize changes to a service with those present in the registry. Upon any changes to a service in the registry, Oracle Service Bus provides notification of the change on the Auto-Import Status page which lists all out-of-sync services. You can then synchronize the service in the Oracle Service Bus Console with the corresponding service in the UDDI registry."
    This setting seems to automatically update the endpoint of the business service wihtout that administrator having to do anything, but what is actually being done? Is the service bus updating the endpoint as soon as it has been notified of a change or when i view/call the service is the endpoint being looked up?
    Am I missing something??
    Edited by: user498458 on Apr 27, 2009 11:30 AM

    I took your advice and re factored the Receive class so it had all the functionality I needed except two methods which would then be overridden in the derived classes. What I had a hard time understanding is once an object of class say SpecialReceive extends Receive it can be referred to as Receive yet still maintain that it's a SpecialReceive.
    What I mean is if I give a Receive object to some method and this method has no idea that this object is actually SpecialReceive and it calls a method say run() which gets overridden by the SpecialReceive. I thought that since this method has no idea what type of Receive this object is it will execute Receive's run(). But it actually does know what type of class it is and it executes the right run() method (the one that SpecialReceive overrides).
    After I realized this there is no more need for casting.
    Thanks everyone for your contributions.

  • How to use 2 primary key in 1 table

    Hi,
    When i creating the table,in this the following are the columns Name,Street,City,Pin in this they give some rules the column Name & City as Primary Key. But when type the query it shows the error table contains one primary key, how i do this? Tell the mistakes

    Hi,
    Welcome to the forum!
    Whenever you have a question, please post your code. Ithelps people understand what the problem is. and allows them to test ideas.
    1000492 wrote:
    Hi,
    When i creating the table,in this the following are the columns Name,Street,City,Pin in this they give some rules the column Name & City as Primary Key. But when type the query What do you mean by "But when type the query"?
    Do you mean "But when I run this query ..."?
    it shows the error table contains one primary key, how i do this? What is the query you're running? What are the results? Did you expect other results? What results did you expect? Why?
    Tell the mistakesThere are not necessarily any mistakes.
    By definition, a table can never have more than 1 primary key. (If needed, a table can have any number of unique keys, that are like primary keys in everything but name.)
    Any key, primary or unique, can be composed of 1, 2, 3 or more columns.

  • How can i set primary key after creating a table ?

    hi friends
    thank you for all the support you have given me . i have doubt ,can we set primary key for a column after creating the table
    I have added a column named idno after creating the table . i want to set that column as primary key . i tried this
    table name = address
    column name = idno
    ALTER TABLE ADDRESS MODIFY (idno PRIMARY KEY(idno))
    ,but not working
    if anbody knows the solution pls reply
    thanks and regards
    nev

    how does the other users know which is the primary key for this table?....the other user needs to execute this query...and modify the query accordingly
    select aa.table_name,aa.column_name,aa.constraint_name,bb.constraint_type
    from user_cons_columns aa,user_constraints bb
    where aa.constraint_name = bb.constraint_name
    and aa.table_name = 'TEST_EMP' and bb.constraint_type = 'P';

  • FindByPrimaryKeys with multiple primary keys

    Hi, I have a table which has a primary key over 2 fields.
    I have learned that in this case, I must leave out the <primkey-field> tag from my ejb-jar.xml. In my Entity Bean's Home interface, do I still need to declare a findByPrimaryKey finder method or do I leave it out?
    Thanks!

    Hi,
    When you have primary key in 2 fields, then you have to combine them into a class called primary key class.
    And yes in your ejb-jar.xml the value for <primkey-field> will be left empty and the value for tag <primkey-key-class> would be the name of your primary key class that you generated. Otherwise, the normal valu would be java.lang.String.

Maybe you are looking for

  • What RAID drivers do I use

    Hello, In my infinate wisdow I scrambled the brains of my unit  :rolleyes_anim:and now must start from scratch. I cannot find the floppy disk that came with my logic board and want to know what drivers do I use to set up my RAID0 during the initial p

  • Where to update latest SAPGUI

    I've installed the Netweaver Trial version and the SAPGUI provided on the DVD (ABAP Objects book). There is recommended to upgrade online to the latest SAPGUI version. Does anybody know the URL to upgrade? any help is apreciated. regards Michael

  • How can I switch pages?

    I already returned my Nano (6) same day I received it because I couldn't use the touchscreen at all.  I tried residing and reloading songs, but to no avail.  Support authorized a return at which time they performed diagnostics and found nothing wrong

  • Will iWeb work with Aperture 3 if I move from iPhoto to Aperture?

    I currently use iPhoto, and have an iWeb site. Is there any reason that iWeb and my published site would not continue to work if I import all of my iPhoto library into Aperture 3 and then stop using iPhoto? I am considering moving from iPhoto to Aper

  • Reg:Deploy objects to Cloud

    Hi !      I had reset the sftp user password . And using all the details " SFTP username , password & hostname " properly with port 22. But I am getting the error "unable to connect to sftp server with provided details. Ensure that the correct detail