Master-detail with auto-generated primary key(master)

Hello,
I have the following master-detail setup:
Master - block A primary key is: codeA
Detail - block B
codeA is genrated only at commit time and is obtained from a sequence.
User needs to add detail records. This is easy to do since he has to click on the insert icon on the toolbar. At commit time, use commit_form.
Prob: the requirements as asked by the client is to add a button (which we will label INSERT DETAIL). When the user click on the button, it opens a window where he can enter the detail info then click on save. This should bring him back to the master-detail form and the record in the detail block is inserted.
What is the problem here ? since the detail block has the foreign key tied to the master primary key, the window-form (with the call_form) that we opened for the detail entry won't be able to save since at this point we still have not assigned a value for the primary key (and hence a value for the foreign key).
Possible Suggestions:
-Use a temp database table to hold the detail record from the second form and use it to transfer values to the detail record in the master-detail
-Use a global record group
-We can't use parameter list to pass back these values.
So my question is:
What would be the most efficient way to have an insert button on the detail block that would allow the user to have a pop up where he can insert his values and then be brought back to the master-detail.
Thanks.

Hello again,
May be I was not clear enough.
Scenario 1: We use the master-detail form as is with the default oolbar. In this case, the user can insert the detail records one by one without needing the primary-foreign key value since this is handled by default.
Once we save the form (commit_form), I use the pre-insert trigger to get the master block primary key generated from the sequence and since the detail block key is copied from this value, both are saved correctly and it is the end of the story.
Scenario 2: As explained in the initial post, the user will populate the detail records one by one by clicking on the -INSERT DETAIL- button and hence has a window where he can insert the detail info and then be brought back to the master-detail form every time he enters a new detail record.
The problem here is that I can't generate the primary key for the master block since the client has the following requirement:
The user can always change his mind and not complete, meaning save the form, his process
As such, the key should be generated in the last step before Commit.

Similar Messages

  • Creating entity beans with auto numbered primary key

    I have two entity bean with a CMR between them. I am successfully creating the first one but when I try and create the child entity bean I get a NullPointerException.
    Now I think this is because the gernerated code tries to get the primary key of the created entity bean and this is not set as it is set using a auto number in the database (An oracle sequence and trigger).
    Is there anyway i can get round this problem?
    Thanks in advance,
    Adrian

    This is the auto generated code:
         public dmd.sync.ejbs.entity.AppliancePackInfoLocal create_Local(dmd.sync.dataobjects.dto.AppliancePackInfoDTO appliancePackInfoDTO, dmd.sync.ejbs.entity.AmppLocal amppLocal) throws javax.ejb.CreateException, java.rmi.RemoteException {
              BeanO beanO = null;
              dmd.sync.ejbs.entity.AppliancePackInfoLocal result = null;
              boolean createFailed = false;
              boolean preCreateFlag = false;
              try {
                   beanO = super.createBeanO();
                   dmd.sync.ejbs.entity.AppliancePackInfoBean bean = (dmd.sync.ejbs.entity.AppliancePackInfoBean) beanO.getEnterpriseBean();
                   preCreateFlag = super.preEjbCreate(beanO);
                   bean.ejbCreate(appliancePackInfoDTO, amppLocal);
                   Object ejsKey = keyFromBean(bean);
                   result = (dmd.sync.ejbs.entity.AppliancePackInfoLocal) super.postCreate_Local(beanO, ejsKey, true);
                   bean.ejbPostCreate(appliancePackInfoDTO, amppLocal);
                   super.afterPostCreate(beanO, ejsKey);
    It must be falling over on the last line as it calls the ejbPostCreate fine.

  • CMP with auto-increment primary key.Please help

    Hi all,
    I new with EJB technology so please bear with me.
    Env: 2k Server, SQL 2k Server
    Sun One(Forte EE) to develop and deploy CMP
    I got the servlet to load the data from CMP's business mehods
    is fine. Calling the findPrimaryKey is OK too. Even when I try to insert the row into DB is OK. At this time I make key PK is int AND NOT
    AUTO INCREMENT everything is OK. In the ejbCreate method
    I called setPK, setName ...It's fine.
    The problem comes when I try to make the PK(still int) to be auto-increment field.In ejbCreate not call setPK because of in SunOne IDE, under the J2EE RI tab of EJB Module property, the Auto generate SQL I set to false so that I can
    modify the SQL statement under SQL Deployment.createRow not taking the PK. I thought that will do it but it doesnot like it at all (I got Exception with transaction rollback)I just want to insert a single row with ID and name that's all.
    Then I changed the SQL statment take PK and changed the Auto Generate SQL to True and in ejbCreate the PK as one of the args and called setPK this time with null object. It doesn't like neither.(Exception Cannot set the primary key with null. That is reasonable.)
    I thought using EJB fast and clean technique would help developer to develop application with easiness.
    So I realy stuck with this, I wonder ejb 2.0 support for auto increment at all because I would like to take advantage of the auto increment feature of the DB without writing the PrimaryKeySequence generator at all.
    Am I missing something with this? May be just config thing to tell
    that my PK is auto-increment field so that when the ejbCreate called it knows not taking the PK or even not asking to call setPK in ejbCreate.
    Any help would appreciated.

    Check out this thread, there's a bunch of good info:
    http://www.theserverside.com/patterns/thread.jsp?thread_id=4976

  • JDO Auto Generate Primary Key

    Hi
    I am working with JDO.
    I want to auto generate the primary key value that should increment for each entry into database.
    How can i do it, please guide me.
    Any link or doc will be appreciated.
    Regards
    Osman

    There is only one answer to "how I do this" questions: read the manual.
    Any link or doc will be appreciated.Google. Seriously dude, a forum is not your personal information service - go make some effort yourself. Come back when you have an actual problem that you need help with.

  • How to "auto" generate "Primary Key" in custom table?

    Hi Folks,
    Requirement:
    I need a function module or program that can create automatically a primary key.
    Scenario:
    I have a program that creates an entries and save it to a custom table at the same time, but a primary key should always be generated respective to the entries saved.
    Example:
    Material(MATNR) 4001001, Plant(WERKS) XX01, ID[Primary Key-auto generated]
    (I'm thinking of a similar concept/logic on how a unique IDOC number is being generated or how SAP standard creates a unique entry)
    I try to look for any SAP FM that can generate a PK, but there's no luck.
    Thanks.
    Regards,
    Jun

    Hi Keshu and All,
    The links are helpful, however:
    #1. I don't have authorization to create a new object in transaction SNRO, but the way I see the objects in SNRO is just for defining the length(number of characters) for the ranges that will be use if I'm not mistaken.
    #2. FM NUMBER_GET_NEXT - yes it can populate incremental unique entries but it's only occurring at runtime ?? So when the program get terminated it's not being saved nowhere.
    So after if I use FM NUMBER_GET_NEXT, I always have to look for all the last primary key in my custom table, then target it as my starting point for creating a new PK.  I think this will give a performance issue, any comments?
    For better visualization, I have scenario:
    1.  (ZQ_CREATE_PK) Create unique incremental PK for material, batch, so on..
    2.  Append line/entries to ZQ_TABLE
    3.  Repeat #1 and #2
    4.  User exits the program
    5.  Back to 1 --> At this point, I need to get the "LATEST" PK then start this as a starting point again to generate PK and append it to ZQ_TABLE
    I'm assuming that SAP has other SAP FMs related in creating this scenario.   Similar to IDOC # creation..
    Thanks.

  • CMP with Auto-increment Primary Key problem

    I'm trying to set a column as IDENTITY in PointBase and have the app server utilize this in the CMP beans. I followed the instructions from the tutorial:
    - In the deployment descriptor, the primary key class is defined as a java.lang.Object. The primary key field is not specified.
    - In the home interface, the argument of the findByPrimaryKey method must be java.lang.Object.
    - In the entity bean class, the return type of the ejbCreate method must be a java.lang.Object.
    Below is (a fragment of) my deployment descriptor:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
    <display-name>CMPModule</display-name>
    <enterprise-beans>
    <entity>
    <display-name>DocState</display-name>
    <ejb-name>DocState</ejb-name>
    <home>com.sun.itstar.j2ee.projectdocmgt.ejb.DocStateHome</home>
    <remote>com.sun.itstar.j2ee.projectdocmgt.ejb.DocState</remote>
    <local-home>com.sun.itstar.j2ee.projectdocmgt.ejb.LocalDocStateHome</local-home>
    <local>com.sun.itstar.j2ee.projectdocmgt.ejb.LocalDocState</local>
    <ejb-class>com.sun.itstar.j2ee.projectdocmgt.ejb.DocStateBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>java.lang.Object</prim-key-class>
    <reentrant>False</reentrant>
    <abstract-schema-name>DocState</abstract-schema-name>
    <cmp-field>
    <field-name>name</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>description</field-name>
    </cmp-field>
    <cmp-field>
    <field-name>color</field-name>
    </cmp-field>
    </entity>
    In the admin-serv/logs directory I get the follow message (bad place for the logs, took me a while to find where it was putting it!):
    [24/Sep/2002:16:33:57] WARNING ( 4165): Validation error in bean DocumentType: Warning: All primary key columns in primary table DOCUMENT_TYPE of the bean corresponding to the generated class com.sun.itstar.j2ee.projectdocmgt.ejb.DocumentTypeBean_387898907_JDOState must be mapped to key fields.
    Map the following primary key columns to key fields: DOCUMENT_TYPE.ID. If you already have fields mapped to these columns, verify that they are key fields.

    Great! This worked. Here are some clear steps:
    1. delete the field from the CMP
    2. delete any business methods that you might have for the field
    3. go to the properties of the bean, find the primary key property. Set the property to Unkown Primey Key Class (java.lang.Object)
    Now there is a bigger problem. CMR fields. In ejbPostCreate() the bean gets its own pk and looks up other related beans. Now that I have removed the accessor to the pk field (and the pk field from the bean), how do I lookup the relationships?
    I need some method that I can call from within ejbPostCreate() that will return the primary key...
    I tried adding the field back in but not as the primary key. That generated an exception that said you cannot do that. If the field is the pk it must be marked as the pk.
    Any ideas?

  • PRIMARY KEY(MASTER)를 REFERENCE하는 FOREIGN KEY 찾는 SQL

    제품 : ORACLE SERVER
    작성날짜 : 2004-03-12
    PRIMARY KEY(MASTER)를 REFERENCE하는 FOREIGN KEY 찾는 SQL
    ========================================================
    $sqlplus sys/manager(SYS user 로 login 함)
    sql> select c.name constraint_name
    from dba_objects a,
    cdef$ b,
    con$ c
    where a.object_name = 'TABLE_NAME'
    and a.object_id = b.robj#
    and b.con# = c.con#
    /

    Hello again,
    May be I was not clear enough.
    Scenario 1: We use the master-detail form as is with the default oolbar. In this case, the user can insert the detail records one by one without needing the primary-foreign key value since this is handled by default.
    Once we save the form (commit_form), I use the pre-insert trigger to get the master block primary key generated from the sequence and since the detail block key is copied from this value, both are saved correctly and it is the end of the story.
    Scenario 2: As explained in the initial post, the user will populate the detail records one by one by clicking on the -INSERT DETAIL- button and hence has a window where he can insert the detail info and then be brought back to the master-detail form every time he enters a new detail record.
    The problem here is that I can't generate the primary key for the master block since the client has the following requirement:
    The user can always change his mind and not complete, meaning save the form, his process
    As such, the key should be generated in the last step before Commit.

  • 10.1.2 form problem querying master details with underscore

    I have a problem on a form we have were by the user is querying a record and the detail block is bringing through an incorrect record. This occurs on all records that have an underscore "_"
    The form is huge so i am trying to cut down whilst testing but thought i would ask the question to see if its anything obvious.
    basically there are 3 tables all on there own blocks linked by the built in relationships in forms.
    the user queries the top one and the other 2 are set to auto query.
    the problem is with only one primary key that is referenced. This has an underscore in it.
    i.e user brings in top level "1000_0"
    this brings through on all detail records another primary key which is "1000-0" but the top level shows the correct "1000_0".
    Is anyone aware of anything this may be, iwill endeavor to set some testing up.

    ok i have recreated in its most basic concept and still exhibits same problem.
    3 db tables.
    create table testparts
    (part VARCHAR2(50) PRIMARY KEY)
    create table testroute
    (testroutepart VARCHAR2(50),
    testrouteno NUMBER,
    CONSTRAINT pK_testroute_PART PRIMARY KEY (testroutepart,testrouteno)  ENABLE,
    CONSTRAINT FK_testroute_PART FOREIGN KEY (testroutepart) REFERENCES testparts (part) ENABLE)
    create table testroutemat
    testroutepart VARCHAR2(50),
    testrouteno NUMBER,
    testroutemat VARCHAR2(50),
       CONSTRAINT PK_testrouteMAT PRIMARY KEY (testroutepart, testrouteno, testroutemat) ENABLE,
        CONSTRAINT FK_MP_PART FOREIGN KEY (testroutepart) REFERENCES testparts (part) ENABLE
    insert into testparts(part)
    values ('TEST_1');
    insert into testparts(part)
    values ('TEST-1');
    insert into testroute (testroutepart,testrouteno)
    values ('TEST-1',1);
    insert into testroutemat (
    testroutepart,
    testrouteno,
    testroutemat
    values(
    'TEST-1',1,'MATERIAL 1'
    insert into testroutemat (
    testroutepart,
    testrouteno,
    testroutemat
    values(
    'TEST-1',1,'MATERIAL 2'
    commit;Then create a new form.
    This form contains 4 blocks.
    a non db block with one non db item on it where the user types in part.
    then 3 further blocks based on the 3 tables above.
    On the block for testparts this has a default where containing
    part=:ctl.partand a relationship to detail block testroute
    part=testroutepartset this relationship to auto query also.
    Then on the blocks for testroute this has relationship to detail block testroutemat
    TESTROUTE.testroutepart=TESTROUTEMAT.testroutepart and TESTROUTE.testrouteno=TESTROUTEMAT.testroutenoI then have a button on on non db block containing
    go_block('TESTPARTS');
    execute_query(no_validate);you then enter TEST_1 within the non db block non db item. hit button and the other items are shown i.e TEST-1 for the detail items?
    Has anyone any ideas??

  • How can I use a mySQL database schema with numeric auto increment primary key instead of GUID?

    Hello!
    I'm using the TestStand "MySQL Insert (NI)" database schema with GUID as primary key. So everything works fine.
    But I prever using numeric values as primary key, because the database is in conjunction with another database which uses numeric values as primary key.
    Is this possible?
    Has anyone an idea how I can modify the "Generic Recordset (NI)" for use with MySQL?
    Thanks!
    Configuration:
    Microsoft Windows XP
    TestStand 3.1
    MySQL 4.1.12a
    MySQL ODBC 3.51 Driver
    Brosig

    Adam -
    The TestStand Database Logging feature does not allow you to run a separate SQL command after executing the command for a statement(table), so I do not think that you can use an auto incrementing column for the tables. There is just no way to get it back in a generic way. One option that I tried is something similar to the Oracle schema where you call a store procedure to return a sequence ID for each record that you want to add.
    So you would have to create the following sequence table in MySQL:
    CREATE TABLE sequence (id INT NOT NULL);
    INSERT INTO sequence VALUES (0);
    Then create a stored procedure as shown below that will increment the sequence value and return it in a recordset:
    CREATE PROCEDURE `getseqid`()
    BEGIN
            UPDATE sequence SET id=LAST_INSERT_ID(id+1);
            SELECT LAST_INSERT_ID();
    END
    Then update the MySQL tables to use INT primary and foreign key values, so the TestStand MySQL SQL file to create all tables would have text like this:
    CREATE TABLE UUT_RESULT
     ID    INT  PRIMARY KEY,
    ~
    CREATE TABLE STEP_RESULT
     ID    INT  PRIMARY KEY,
     UUT_RESULT   INT  NOT NULL,
    ~
    Then update the schema primary and foreign key columns in the TestStand Database Options dialog box to be INT to match the table. For the primary key columns, you will have to set the Primary Key Type to "Get Value from Recordset" and set the Primary Key Command Text to "call getseqid()". This will call the stored procedure to determine the next value to use as the ID value.
    Hope this helps...
    Scott Richardson
    National Instruments

  • Multiple level of Master Detail with ShowOneTab

    I am developing an ADF application using JDeveloper.
    Let us assume that we have three entities A,B and C. I have created three view objects and two View Link objects to implement three level Master-Detail relationship.
    I have created master table - detail table on a jspx page where master is entity A and detail is entity B. Detail table is in a showDetailItem component in showOneTab which works fine.
    Now I have the requirement to create another level of master detail hierarchy between entity B and C. The master of this relationship is B, which is displayed on one showDetailItem tab as stated above. While the detail for entity C must display on second tab (showDetailItem).
    I have set the partial trigger id of third table to masterDetail2 (id of the entity B table now serving as master). I have also set the AutoSubmit property of this table to true. But the data is not refreshed, it always displays the first set of records.
    Please suggest what I can do or if I am missing something to implement the solution?
    Regards,
    Amir

    Hi,
    I think this is because PPR doesn't work on hidden components (that are components that are not rendered). Try and add a listener to the tab canvas that then on changing the tabs, re-executes the iterator for this table
    Frank

  • Sequences to generate primary keys

    Hi,
    A question on using sequences to generate primary keys. We have a table and in all environments, test, uat, prod, a sequence exists to generate the primary key for the table. This table is a reference table and is not updateable by the users.
    When developing scripts to insert records into the table, the developers are currently not using the sequence but typing in unique numbers so data scripts consist of something like this:
    INSERT INTO EMPLOYEE_GROUP
    (employee_group_id, code, description,...)
    VALUES
    (45,'sdf','sdfsdfsf');
    INSERT INTO EMPLOYEE_GROUP
    (employee_group_id, code, description,...)
    VALUES
    (46,'sdf','sdfsdfsf',...);
    a) Is this normal practice?
    b) Sometimes they are using the sequence to generate the primary key in development but then hardcoding the number in the script so in development the sequence might be at 160, but in the other environments the sequences will still be at one. Is this also normal practice?
    My usual method in developing scripts is to use <seqeunce>.nextval but it's somewhat incompatitble in the current environment.

    You are using a surrogate, or synthetic primary key. For a primary key generated in this way, the value is inconsequential. All that matters is that it is unique and the tables with foreign keys into it, if any, also have that value set properly. But it doesn't matter if the value is 1, 100, 12344, 2222222222, etc. All you care about is the uniqueness.
    If you create the data properly then child records and their parents should be correct in all systems you mention, it's just that the actual value of the key will differ and that's fine. You care about the relationship of the records, not the value of the synthetic keys.

  • Generate  primary key automatically

    Hi, I'd like to know how to generate primary keys automatically with JHeadStart because when I try to make an insert into a table, the page gives me the option of insert the primary key of the register.
    Thanks a lot

    I have a table which have 2 fields, one of those is the primary key, the other is the description.
    I have established the primary key as a DBSequence, but when I try to insert a new record testing the service, appears a negative number in the primary key and instead of that I want to appear the correspondent key, or if doesn't appear the correct value, the insert be done correctly.
    At least I change manually the value if this key, the insert can't be done.

  • How to impliment a auto increamenting  primary key feature in ADF ??

    How to implement an auto incrementing primary key feature in ADF ( With out using database Triggers)
    Edited by: Dinil Mithra on Apr 24, 2009 2:28 AM
    Edited by: Dinil Mithra on Apr 24, 2009 2:59 AM

    Dinil,
    Create a sequence in the database.
    Read section 4.11.5 of the Fusion Developer's Guide - which has sample code to get the next sequence value from Java without a database trigger.
    John

  • What to use in jpa from self generated primary key ?

    Is it described somewhere what strategy to use with JPA when primary key are self generated by a trigger into the table ?
    Thank You

    Please see this link http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Primary_Keys_through_Triggers

  • How generate primary key atumatically in jdeveloper 10g

    Hi,
    I am using jdev 10g. I created a fusion web applicaton.
    I am not getting any option to generate primary key from sequence automatically.
    In Jdev11g we can create by trigger easily.
    Please help
    Thanks
    Raj

    Hi Raj,
    Check this link
    [http://download.oracle.com/docs/html/B25947_01/bcentities006.htm#sm0147|http://download.oracle.com/docs/html/B25947_01/bcentities006.htm#sm0147]
    Regards,
    Vikram

Maybe you are looking for

  • Mac's using a Windows Print Server

    I am an administrator for a dual-platform school district (elementary and middle schools). We run both AD & OD, and all of our Mac's are bound to both AD & OD. Our users authenticate to Active Directory. My issue is printing from our Mac's (MacBooks

  • Itunes keeps quiting when ipod is connected

    every time i connect my ipod it starts to update but then itunes gets an "unexpected error" and ive killed itunes and installed the newest itunes and everything even restored my comp. but nothing works PLEASE HELP THANKS

  • Sql Query in WebDynpro

    Hi Experts,      Can any one tell me how to use SQL Query in WebDynpro Java to access the Database? Please mention the code where to use and the configuration to be done. Thanks in Advance Naveen

  • Cropping + Changing Canvas Size

    Hello, I have a problem (because I'm a beginner in Photoshop), and it's that when I crop and image and try to change the canvas size - I change the size because I'm using another type of paper - (and anchor the image to the top left), the image looks

  • How to clean recent used fonts dropbox on Pages '09?

    Hi everyone! I've searched a lot but can't resolve this. I can't clear my recent used fonts on Pages '09. I'm not talking about the box opened with cmd+T, I'm talking about the dropbox next to the font size, bold, italic, etc. I've tried to delete th