Solved: ADF BC and primary keys - how to implement without using triggers

Using the following OBE as an example:
http://www.oracle.com/technology/obe/obe9051jdev/ADFWorkshop/BuildingADFApplicationsWorkshop.htm
There is just one view that has CustomerId defined as a primary key, where the value for the primary key comes from the customer_seq sequence.
How do you create the model using ADF BC entity to create an entity object that has a primary key that needs to be populated by a sequence table when inserted WITHOUT using a trigger?
Basically I want to just use ADF BC instead of toplink in the OBE. We do not use triggers to insert primary keys, so this example is a good match for what I need.
Can someone help me out. How do I adjust the model to use just ADF BC - how do I define the entity object to use a sequence. Do I just override the create method in the impl? Is it that simple? Or is there a way to do this point and click in the entity tool.
Thanks!

I'm not the dba (or one of several) - so don't shoot the messenger... the dba's do not like to use triggers in the code. I have been told that this has caused too many problems in application development.
I don't ask why, just deal with the fallout.
I did try using the following code in a create method:
protected void create(AttributeList attributeList)
super.create(attributeList);
SequenceImpl s = new SequenceImpl("customers_seq", getDBTransaction());
// this.setCustId(s.getSequenceNumber());
this.createPrimaryKey(s.getSequenceNumber());
When I run the test program for the module, I get a new entry with the id empty and greyed out. I was hoping that this would be filled in on the actual insert, but no joy. As soon as I try to commit, I get an error:
(oracle.jbo.AttrValException) JBO-27014: Attribute CustId in CustomersWSView is required)
So what needs to be done?
Message was edited by:
klee

Similar Messages

  • Best practices with sequences and primary keys

    We have a table of system logs that has a column called created_date. We also have a UI that displays these logs ordered by created_date. Sometimes, two rows have the exact same created_date down to the millisecond and are displayed in the UI in the wrong order. The suggestion was to order by primary key instead since the application uses an oracle sequence to insert records so the order of the primary key will be chronological. I felt this may be a bad idea as a best practice since the primary key should not be used to guarantee chronological order although in this particular application's case, since it is not a multi-threaded environment, it will work so we are proceeding with it.
    The value for the created_date is NOT set at the database level (as sysdate) but rather by the application when it creates the object which is persisted by Hibernate. In a multi-threaded environment, thread A could create the object and then get blocked by thread B which is able to create the object and persist it with key N after which control returns to thread A it persists it with key N+1. In this scenario thread A has an earlier timestamp but a larger key so will be ordered before thread B which is in error.
    I like to think of primary keys as solely something to be used for referential purposes at the database level rather than inferring application level meaning (like the larger the key the more recent the record etc.). What do you guys think? Am I being too rigorous in my views here? Or perhaps I am even mistaken in how I interpret this?

    >
    I think the chronological order of records should be using a timestamp (i.e. "order by created_date desc" etc.)
    >
    Not that old MYTH again! That has been busted so many times it's hard to believe anyone still wants to try to do that.
    Times are in chronological order: t1 is earlier (SYSDATE-wise) than t2 which is earlier than t3, etc.
    1. at time t1 session 1 does an insert of ONE record and provides SYSDATE in the INSERT statement (or using a trigger).
    2. at time t3 session 2 does an insert of ONE record and provides SYSDATE
    (which now has a value LATER than the value used by session 1) in the INSERT statement.
    3. at time t5 session 2 COMMITs.
    4. at time t7 session 1 COMMITs.
    Tell us: which row was added FIRST?
    If you extract data at time t4 you won't see ANY of those rows above since none were committed.
    If you extract data at time t6 you will only see session 2 rows that were committed at time t5.
    For example if you extract data at 2:01pm for the period 1pm thru 1:59pm and session 1 does an INSERT at 1:55pm but does not COMMIT until 2:05pm your extract will NOT include that data.
    Even worse - your next extract wll pull data for 2pm thru 2:59pm and that extract will NOT include that data either since the SYSDATE value in the rows are 1:55pm.
    The crux of the problem is that the SYSDATE value stored in the row is determined BEFORE the row is committed but the only values that can be queried are the ones that exist AFTER the row is committed.
    About the best you, the user (i.e. not ORACLE the superuser), can do is to
    1. create the table with ROWDEPENDENCIES
    2. force delayed-block cleanout prior to selecting data
    3. use ORA_ROWSCN to determine the order that rows were inserted or modified
    As luck would have it there is a thread discussing just that in the Database - General forum here:
    ORA_ROWSCN keeps increasing without any DML

  • APEX and Primary Keys

    Hello:
    I ran into a situation where we have a table with no primary key set. When I tried to create a form, APEX told me that a primary key must be set in order to run reports. This makes complete sense. No issue here. For some of our tables, we can set the primary key.
    The issue we have is that some of our tables are using "natural primary keys". We have tables where more than one column is designated as a primary key. For example, if I have a table with patient_id, organization_id, insurance_id, and expiration date. In order for a record to be unique in this table both the organization_id and insurance_id are set as primary keys.
    If I attempt to create a form in APEX using these tables which have more than one primary key, how will APEX know that there are more than one primary key?
    Thanks for the input.

    In that case you could also use rowid and instead of views. I have an example showing how
    this can be done:
    http://apex.oracle.com/pls/otn/f?p=31517:157
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Replication and Primary Keys

    I am investigating replication for a client of mine who needs to have two separate sites inserting and editing data into identical schemas, but would like to sync the two databases on a regular (nightly?) basis. I bought an Oracle Replication book, and from it I have figured I need to implement advanced replication...but I have not found the answer to this question:
    How does one handle Primary Keys for new records? The client is currently using sequences on both ends to generate the keys...do I simply set up the sequences so that one site uses 0 to 1 million, and the other site uses 1 million to 2 million, etc?
    Or is there a more 'automatic' way that Oracle can handle replication of primary key columns? Maybe by using compound primary keys (ID column and location column)?
    Thanks in advance,
    Chris DuBuc
    Buke Incorporated

    For two sites, the easiest is probably to have the sequences on one site generate even keys and the sequences on the other site generate odd keys. For more than that, you'll probably want to give each site a different range of values, but that tends to be more painful to deal with than odd/even.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Difference between Unique key and Primary key(other than normal difference)

    Hello,
    1).Can any one tell me any other difference between Unique key and Primary key other than it having NULLs.
    2). What is the difference the words 'DISTINCT' and 'UNIQUE' in a sql query.
    Thanks in advance.

    Hi
    If you don't believe me than see the documentation in
    OTN.
    Ott Karesz
    http://www.trendo-kft.hu
    SQL> create table scott.tbl_clob
      2  (sss CLOB)
      3  /
    Tabelle wurde angelegt.
    SQL> insert into scott.tbl_clob values('wrwrwrw')
      2  /
    1 Zeile wurde erstellt.
    SQL> insert into scott.tbl_clob values('wrwrwrw')
      2  /
    1 Zeile wurde erstellt.
    SQL> select distinct sss from scott.tbl_clob
      2  /
    select distinct sss from scott.tbl_clob
    FEHLER in Zeile 1:
    ORA-00932: nicht übereinstimmende Datentypen
    SQL> select unique sss from scott.tbl_clob
      2  /
    select unique sss from scott.tbl_clob
    FEHLER in Zeile 1:
    ORA-00932: nicht übereinstimmende Datentypen
    SQL> select distinct to_char(sss) from scott.tbl_clob
      2  /
    TO_CHAR(SSS)
    wrwrwrw
    SQL> select unique to_char(sss) from scott.tbl_clob
      2  /
    TO_CHAR(SSS)
    wrwrwrw
    SQL>

  • Dynamic SQL Joining between tables and Primary keys being configured within master tables

    Team , Thanks for your help in advance !
    I'm looking out to code a dynamic SQL which should refer Master tables for table names and Primary keys and then Join for insertion into target tables .
    EG:
    INSERT INTO HUB.dbo.lp_order
    SELECT *
    FROM del.dbo.lp_order t1
    where not exists ( select *
    from hub.dbo.lp_order tw
    where t1.order_id = t2.order_id )
    SET @rows = @@ROWCOUNT
    PRINT 'Table: lp_order; Inserted Records: '+ Cast(@rows AS VARCHAR)
    -- Please note Databse names are going to remain the same but table names and join conditions on keys
    -- should vary for each table(s) being configured in master tables
    Sample of Master configuration tables with table info and PK Info :
    Table Info         
    Table_info_ID    Table_Name    
    1        lp_order    
    7        lp__transition_record    
    Table_PK_Info        
    Table_PK_Info_ID    Table_info_ID    PK_Column_Name
    2                1    order_id
    8                7    transition_record_id
    There can be more than one join condition for each table
    Thanks you !
    Rajkumar Yelugu

    Hi Rajkumar,
    It is glad to hear that you figured the question out by yourself.
    There's a flaw with your while loop in your sample code, just in case you hadn't noticed that, please see below.
    --In this case, it goes to infinite loop
    DECLARE @T TABLE(ID INT)
    INSERT INTO @T VALUES(1),(3),(2)
    DECLARE @ID INT
    SELECT @ID = MIN(ID) FROM @T
    WHILE @ID IS NOT NULL
    PRINT @ID
    SELECT @ID =ID FROM @T WHERE ID > @ID
    So a cursor would be the appropriate option in your case, please reference below.
    DECLARE @Table_Info TABLE
    Table_info_ID INT,
    Table_Name VARCHAR(99)
    INSERT INTO @Table_Info VALUES(1,'lp_order'),(7,'lp__transition_record');
    DECLARE @Table_PK_Info TABLE
    Table_PK_Info_ID INT,
    Table_info_ID INT,
    PK_Column_Name VARCHAR(99)
    INSERT INTO @Table_PK_Info VALUES(2,1,'order_id'),(8,7,'transition_record_id'),(3,1,'order_id2')
    DECLARE @SQL NVarchar(MAX),
    @ID INT,
    @Table_Name VARCHAR(20),
    @whereCondition VARCHAR(99)
    DECLARE cur_Tabel_Info CURSOR
    FOR SELECT Table_info_ID,Table_Name FROM @Table_Info
    OPEN cur_Tabel_Info
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SELECT @whereCondition =ISNULL(@whereCondition+' AND ','') +'t1.'+PK_Column_Name+'='+'t2.'+PK_Column_Name FROM @Table_PK_Info WHERE Table_info_ID=@ID
    SET @SQL = 'INSERT INTO hub.dbo.'+@Table_Name+'
    SELECT * FROM del.dbo.'+@Table_Name+' AS T1
    WHERE NOT EXISTS (
    SELECT *
    FROM hub.dbo.'+@Table_Name+' AS T2
    WHERE '+@whereCondition+')'
    SELECT @SQL
    --EXEC(@SQL)
    SET @whereCondition = NULL
    FETCH NEXT FROM cur_Tabel_Info
    INTO @ID, @Table_Name
    END
    Supposing you had noticed and fixed the flaw, your answer sharing is always welcome.
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Unique and primary key

    column with unique constraint + not null constraint = primary key! (to some extent) Is it correct?
    I invite your ideas

    http://www.techonthenet.com/oracle/unique.php
    http://www.allapplabs.com/interview_questions/db_interview_questions.htm#q13
    Difference between Unique key and Primary key(other than normal difference)

  • Table and Primary Key Case Sensitive in Automated Row Fetch

    Why are the table and primary key fields case sensitive in the Automated Row Fetch process? I'm debugging an error in this process and I'm not sure what the case should be.

    Russ - It's a defect of sorts. Use upper case in the process definition. I don't think these processes will work with tables or columns whose names are not known to the database as upper-case values, i.e., defined using double-quoted non-upper case.
    Scott

  • Reinstalling AE and PP due to an error with dynamic link. Where do i find the program install? And tips on how to reinstall without messing things up? last question is, does my recent files and saves work after the reinstall?

    I have allready bought the programs, but need to reinstall AE and PP due to an error with dynamic link.
    Where do i find the program install?
    And tips on how to reinstall without messing things up?
    last question is, does my recent files and saves work after the reinstall?
    Thank you

    karianne wrote:
    I have allready bought the programs, but need to reinstall AE and PP due to an error with dynamic link.
    Where do i find the program install?
    Which versions? Which operating system?
    Try Download and Installation Help

  • How to create session and end the session in atg without using ootb

    can anyone send the code for creating session(Login) and ending(Logout) session in atg without using ootb.
    thankyou!

    It is plain simple and is plain old request.getSession(false) and then invalidate the session , but why do you want to do it separately . ATG works behind scenes to associate lot of attributes to the session when log in happens and then deassociates them when log out happens , SessionManager component is also helpful in security , can you state why exactly would you want to do it?

  • I can't set up gmail in my iPad 2. Keep on saying ' can't connect with SSL and ask me whether to connect without using SSL, then I press 'yes' and it said again IMAP is not working and tell me to see network connection and incoming mail server.

    I can't set up gmail in my iPad 2. Keep on saying ' can't connect with SSL and ask me whether to connect without using SSL, then I press 'yes' and it said again IMAP is not working and tell me to see network connection and incoming mail server. No idea how to do anymore. Already tried to figure out. But not work. Can anyone pls help me?

    Nope, doesn't pass verification. I get the spinner for a minute or so, then the alert about setting it up without SSL. Are you suggesting I disable Fetch and Push BEFORE I enter the account details? Because I never get past the account details screen, unless I choose "Set up without SSL" after the warning.

  • Is there any way to connect my Apple wireless/bluetooth trackpad and keyboard to my Mac Mini without using a wired or usb keyboard?

    Is there any way to connect my Apple wireless/bluetooth trackpad and keyboard to my Mac Mini without using a wired or usb keyboard?

    Well, I read that already, but I am trying to start up my Mac mini(new purchase) and I cannot get to all the system preferences etc since I cannot get past the startup screens. The site also mentioned waiting to turn on the keyboard until a language was requested. Neither language screen worked. I feel as though I'm just about ready to throw in the towel.

  • ADF and Primary Key

    Hi!
    I'm using PostgreSQL as the DB and set for PK an attribute named ID that's of type serial. It's auto-incremented when the row is go to be inserted.
    I've read in other posts like this one -> Primary key during Insert
    to set type to DBSequence, but later the compiler gives me an error saying DBSequence doesn't exist.
    How can I get this working? Or how can I put a value in ID in the application's code that's de MAX(ID) +1?
    Thanks

    Your first image - setting the type of the id as a DBSequence is correct. What you are saying by doing this is that the database is automatically setting the value of your primary key. This means that when the Entity object does DML, it doesn't require the user to supply the value, it doesn't set it itself, and it retrieves the value as soon as the insert is complete. In Oracle, it would use a "RETURNING" clause - I don't know if Postgres SQL does this.
    Given that DBSequence is saying that the DATABASE is setting the value, I'm not sure what you are trying to do in your second image. You seem to have a Java object that has a getter and setter for the column. I'm not sure what the purpose of this object is, especially if Postgres SQL is setting the id, not the application.
    When you create an Entity Object in ADF Business components, it can optionally write the Java classes that implement the object, so that you can override certain functionality. Choose the "Java" menu option on the Entity Object definition screen and check the appropriate checkboxes to get it to write Java that you can change. If your Entity is named MyEntity, JDeveloper will generate MyEntityImpl,java. If you edit this file, you will see that it already has a getter and a setter for your id. I think that the datatype that it will assign is "Number", not "DBSequence". If you really need to change the getter and setter, do it here.

  • Problem with foreign and primary keys migration from SQL Server to Oracle

    Hi folks, i'm using SQL Developer to migrate from a SQL Server database to Oracle and i'm stuck with a couple issues:
    The worst of them so far is the fact that i can't migrate any of the PKs and FKs. After successfully capturing the SQL Server DB model and converting it to Oracle, when the tool generates the scripts, all ALTER TABLE queries that add the PKs and FKs have their target columns duplicated.
    for example: when i'm trying to migrate a simple table that contains an Id (PK) and Name columns, the tool generates the following scripts:
    PROMPT Creating Table TestTable...
    CREATE TABLE TestTable (
    Id NUMBER(10,0) NOT NULL,
    Name VARCHAR2 NOT NULL
    PROMPT Creating Primary Key Constraint PK_TestTable on table TestTable ...
    ALTER TABLE TestTable
    ADD CONSTRAINT PK_TestTable PRIMARY KEY
    Id,
    Id
    ENABLE
    As for the FKs, the tool duplicates the columns as well:
    ALTER TABLE SomeTable
    ADD CONSTRAINT FK_SomeTable_SomeTable2 FOREIGN KEY
    SomeTable2Id,
    SomeTable2Id
    REFERENCES SomeTable2
    Id,
    Id
    ENABLE
    Does anyone have a clue on how to solve these issues? I'd be greatly thankful for any answers!

    Hi Fernando,
    I was unable to replicate this issue. My primary / foreign keys where defined using unique columns.
    PROMPT Creating Primary Key Constraint PK_Suppliers on table Suppliers ...
    ALTER TABLE Suppliers
    ADD CONSTRAINT PK_Suppliers PRIMARY KEY
    SupplierID
    ENABLE
    I tried a few things like
    capturing twice and renaming both models the same
    renaming the converted models
    but with no luck.
    I think this issue is occuring either at the capture or convert phase.
    1) Are you performing the capture online or offline?
    2) Can you provide a the entire DDL for one of these tables and its indexes to see if I can replicate?
    3) Did the capture or convert fail or have to be redone at any stage ?
    I all else fails I would attempt a capture and convert again using a brand new repository (create a new schema in Oracle and associate the migration repository with it).
    Regards,
    Dermot
    SQL Developer Team
    Edited by: Dermot ONeill on Oct 22, 2009 12:18 PM

  • What is the diffrence between Row id and primary key ?

    dear all
    my question is about creating materialized views parameters (With Rowid and
    With Primary kry)
    my master table contains a primary key
    and i created my materialized view as follow:
    CREATE MATERIALIZED VIEW LV_BULLETIN_MV
    TABLESPACE USERS
    NOCACHE
    LOGGING
    NOCOMPRESS
    NOPARALLEL
    REFRESH FAST ON DEMAND
    WITH PRIMARY KEY
    AS
    SELECT
    BCODE ID, BTYPE BTYPE_ID,
    BDATE THE_DATE,SYMBOL_CODE STOCK_CODE,
    BHEAD DESC_E, BHEADARB DESC_A,
    BMSG TEXT_E, BMSGARB TEXT_A,
    BURL URL, BTIME THE_TIME
    FROM BULLETIN@egid_sefit;
    I need to know is there a diffrence between using (with row id) and (with primary key) on the performance of the query?

    Hi again,
    fast refreshing complex views based on rowids, according to the previous subject.
    (You're example shows that) are not possible.
    Complex remote (replication) snapshots cannot be based on Rowid too.
    for 10.1
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6002.htm#sthref5054
    for 10.2
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm#sthref6873
    So I guess (didn't check it) that this applies ONLY to replication snapshots.
    This is not documented clearly though (documentation bug ?!)
    Documentation states that the following is generally not possible with Rowid MVIEWS:
    Distinct or aggregate functions
    GROUP BY or CONNECT BY clauses
    Subqueries
    Joins
    Set operations
    Rowid materialized views are not eligible for fast refresh after a master table reorganization until a complete refresh has been performed.
    The main purpose of my statements was to try to give a few tips how to avoid common problems with this complex subject, like for example: being able to CREATE an MVIEW with fast refresh clause does not really guarantee that it will refresh fast in the long run (reorganisation, partition changes) if ROWID based, further the rowid mviews have limitations according to the documentation (no group by, no connect by, link see above) plus fast refresh means only to use filter columnns of the mview logs, plus for aggregates you need additional count (*) pseudo columns.
    kind regards
    Karsten

Maybe you are looking for