Primary key issue

Hi all,
I'm new here, and I have a stupid problem, I think. If someone could help me, I'll be grateful.
I have to build a very simple JSP application using a few database tables, providing the base functionality: insert, update, delete, search.
I'm using Oracle 8.1.7, and JDeveloper 9.0.3
One table looks like that:
CREATE TABLE TEST (
sPrimaryKey varchar2(30) not null,
sField varchar2(100)
ALTER TABLE TEST
ADD ( CONSTRAINT test_id_pk
PRIMARY KEY (sPrimaryKey)
I'm using a sequence for generating primary key...
CREATE SEQUENCE test_seq
START WITH 100
INCREMENT BY 1
NOCACHE
NOCYCLE;
... and a trigger before insert for seting the new value of the primary key.
CREATE OR REPLACE TRIGGER BI_TEST
BEFORE INSERT ON TEST
FOR EACH ROW
DECLARE
new_id integer;
BEGIN
select test_seq.nextval into new_id from dual;
:new.sPrimaryKey := 'AAA' || new_id;
END;
I have created a BC4J. How can I insert a new row into that table using a BC4J from an HTML form, within a JSP page, without providing the primary key, by hand, and let the trigger and sequence do that?
Thank you!
Razvan

I'm using a sequence for generating primary key...Change the attribute type for sPrimaryKey to be a DBSequence attribute type. It assumes you have an insert-trigger that fills in the correpsonding numeric column.

Similar Messages

  • ODI - Primary Key issue

    Hi ,
    I have a primary key constraint in the target datastore. Thats mapped to field in the source which is not primary key. How can I check that , when I map from source to target primary key constraint is not violated ( I checked DISTINCT and UNIQUE as filter condition , but its not accepting the format. Give me the exact format)

    Hi ,
    My requirement is like I have a primary key in one of the fields of target column. That field is mapping to a field in source which is not a primary key . Source field can have duplicate values. I have to filter out that values when it enters to the target field. I used "DISTICT" keyword in the target datastore. But that will check only for "DISTINCT" records. I cannot applu "DISTICT" for individual field.
    For EX:
    SOURCE : TARGET
    DEPT CLASS SUBCLASS DEPT(primary key) CLASS
    1 1 1
    1 2 2
    1 3 3
    2 2 1
    2 1 2
    2 3 3
    If I use "DISTINCT" then it will choose ( 1 1,1 2,1 3,2 2,2 1,2 3) . But that will violate the primary key constraint.
    Edited by: rameshchandra85 on Nov 29, 2008 9:11 PM

  • Primary key issue with adf Entry Form.

    Hi All,
    i'm using jdev version 11.1.1.5.0
    use case: i have create simple entry form based on Eo and Vo using database table like student(enrollment no,name address)
    where enrollment no is primary key.
    so when i have create a record i have set enrollment no in entity impl class of this eo create method using some logic based on my need like(20130001)
    for that i have read highest no from database field and assign to enrollment no field when user create record.
    so when user create record second time then enrollment no is 20130002. and other detail like name and address user fill and commit record. and it is fine.
    but problem is that when two user access same form at a time and create record so both have get same primary key like 20130003 because in current time in database maximum value is 20130002.
    so which user  commit record first it record will save on database and second user get error message because of primary key violation.
    so my question is that where we generate primary key value for record so when multiple user access form have get different primary key value. and in my use case i can't use sequence and any autoincrement no
    because i have patter for primary key.
    Thanks in Advance
    Manish

    Hi,
    Dimitar and Frank
    thank for reply.
    How can i apply non-concurrent DB lock can you please explain.(because lock method on entity impl not work when user create new row as per documentation)
    http://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/server/EntityImpl.html#lock__
    i have write following line of code in entity impl class to set primary key value(reqid)-
        @Override
        protected void prepareForDML(int i, TransactionEvent transactionEvent) {
             super.prepareForDML(i, transactionEvent);
            this.setReqid(genReqid());
        public String genReqid() {
            String reqby = this.getReqby();
            String qry =
                "SELECT nvl(MAX(TO_NUMBER(SUBSTR(REQID,7))),0)+1  FROM STM_REQHDR WHERE REQBY=? AND REQTYPE<>'M' and substr(reqid,1,2)<>'MT' AND SUBSTR(REQID,1,3)<>'PAY'";
            PreparedStatement ps = null;
            String no = "";
            try {
                ps = getDBTransaction().createPreparedStatement(qry, 0);
                ps.setString(1, reqby);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    no = rs.getString(1);
                ps.close();
            } catch (Exception e) {
                System.out.println("Exception in Gen req id ==>" + e);
            String reqno = reqby + String.format("%6s", no).replace(' ', '0');
            return reqno;
    but when i run form in debug mode and two user commit concurrent manner only one time code block is executed who first commit. and second user got error message.
    thanks
    Manish

  • Primary Key Issue With Creating Tables

    Hi,
    I have the following scripts to create my two tables in oracle 10g, i was wondering wether or not i had correctly set up my primary key or if there is a better way of doing it than the way i have.
    Here are my two scripts for my tables:
    CREATE TABLE CUSTOMER (
    fname varchar2(15) NOT NULL,
    lname varchar2(20) NOT NULL,
    age varchar2(3) NOT NULL,
    custAreaCode number(5) NOT NULL,
    custNumber number(6) NOT NULL,
    constraint cust_pk PRIMARY KEY (custAreaCode),
    constraint cust_pk2 PRIMARY KEY (custNumber),
    constraint age_chk CHECK (age >=18 AND age <150)
    CREATE TABLE PHONECALL (
    startDateTime smalldatetime NOT NULL,
    custAreaCode number(5) NOT NULL, ---Reference PK From Customer Table
    custNumber number(6) NOT NULL, ---Reference PK From Customer Table
    dialledAreaCode number(5) NOT NULL,
    dialledNumber number(6) NOT NULL,
    crgPerMinute number number (3,1) NOT NULL,
    endDateTime smalldatetime NOT NULL));
    I am not sure if i have referenced the primary keys correctly in the PHONECALL table.
    Thanks in advance :)

    Hi,
    You want like this below ? I think that smalltime data type is not a valid type. Other thing, this is not a rule, but I advice you to put the primary key columns as the first columns of your table. One question: There is no PK on the phonecall table ?
    SGMS@ORACLE10> create table customer (
      2  custareacode number(5) not null,
      3  custnumber number(6) not null,
      4  fname varchar2(15) not null,
      5  lname varchar2(20) not null,
      6  age varchar2(3) not null,
      7  constraint cust_pk primary key (custareacode),
      8  constraint cust_uk unique (custnumber),
      9  constraint age_chk check (age >=18 and age <150)
    10  );
    Table created.
    SGMS@ORACLE10> create table phonecall (
      2  custareacode number(5) not null constraint fk_phone_cusarecode_customer references customer,
      3  custnumber number(6) not null constraint fk_phone_custnumber_customer references customer,
      4  startdatetime date not null,
      5  dialledareacode number(5) not null,
      6  diallednumber number(6) not null,
      7  crgperminute number (3,1) not null,
      8  enddatetime date not null);
    Table created.
    SGMS@ORACLE10> select table_name,constraint_name,constraint_type from user_constraints
    2 where table_name in ('CUSTOMER','PHONECALL') and constraint_type in ('P','U','R');
    TABLE_NAME                     CONSTRAINT_NAME                C
    CUSTOMER                       CUST_PK                        P
    CUSTOMER                       CUST_UK                        U
    PHONECALL                      FK_PHONE_CUSARECODE_CUSTOMER   R
    PHONECALL                      FK_PHONE_CUSTNUMBER_CUSTOMER   RCheers

  • Primary key issue in toplink workbench

    Hi All,
    I am getting No primary keys specified in (xxx is the table name) table error in workbench.
    I my table,don't have any primary keys,i try to do direct to field mapping for all the fields with the table.
    After mapping,was getting this warning.
    Is there any mandatory thing in toplink workbench that we need to have atleast one primary key defined in a table.
    Please let me know!!!!!!!!!!!!
    Appreciate your hekp............

    Yes, it needs to know how to uniquely identify the row to do deletes and updates, etc. If you have no PK, then actually every field is needed to uniquely identify the row, and therefore just slect every field in the MW as being the PK... Note that the PK specified in the MW doesn't have to actually be the PK on the database, it just has to be unique for when TL does update/delete, etc.
    - Don

  • MAP 9.1 - Inventory is scanned but failed during Assessment, Duplicate Primary Key

    Hi MAP team, saw the similar thread but didn't want to hijack it if it's a different root cause.
    We have a client using MAP for data collection that is having failures with generating the assessment. In the MAPToolkitLog, we get this:
    “Microsoft.AssessmentPlatform.MapException: Caught SqlException running the stored procedure [WinClient_Assessment].[LicensingAssessmentProc]. ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'LicensingAssessment_pk'. Cannot
    insert duplicate key in object 'WinClient_Assessment.LicensingAssessment'. The duplicate key value is (4d74950a-3c31-4b7e-9464-12fd8ae03942).”
    Tracing it down it looks like there are two entries for a DeviceNumber under Win_Inventory.SoftwareLicensingProducts, with these two descriptions: “Windows Operating System - Windows(R) 7, RETAIL channel”, and “Windows Operating System - Windows(R) 7, OEM_SLP
    channel”. So two lines are trying to get created for an OEM and a RETAIL line in the LicensingAssessmentProc, causing a duplicate PRIMARY KEY and hence the issue with the assessment. Is this an existing bug and if so is there a quick way to resolve it so we
    can conduct the assessments? The issue is that we cannot run additional scans to improve coverage as it wants us to refresh the assessment before letting us run another scan.
    Thank you,
    Nick

    Following up on this, digging into the data it looks like "Windows(R) 7, OCUR add-on for Ultimate,HomePremium,Enterprise,Professional,ServerHomePremium,Embedded" is getting flagged as an OS and being included in the Win_Inventory.SoftwareLicensingProducts,
    conflicting with the actual OS line. When I deleted those rows the duplicate primary key issue was resolved and we were able to process assessments. Not sure if we can run additional scans on that database, will check soon.
    This is a pretty inconvenient way to get around this bug however, can this be addressed without having to delete SQL rows, or is this an edge case that needs to be caught in the filtering in the next release?

  • Primary Key problem in 11g - Known issue 6894412

    Hi Everyone:
    We are on JDeveloper 11.1.1.4, and JHeadstart 11.1.1.2.46. This thread originally started on the JHeadstart forum and can be seen at: Problem with LOV's in 11g
    We are converting our 10g application to 11g. We have an established Oracle database that does not use pre-populated primary keys that are sequence number. Our database has composite keys and the integrity of those composite keys are established by foreign key constraints to edit tables. This approach has worked extremely well for us for over a decade, the logic of the database has been designed so that the database protects itself through the elimination of cascade deletes where necessary, and cascade deletes as the business logic dictates. This will not be changing.
    In the database tables in which the 10g application has been displayed in the table format, after conversion to 11g, the LOV pop-ups are not working unless the SAVE button (or refresh of the browser) has been pressed. The first LOV pop-up will work, but as soon as you select a value from it, the next LOV pop-ups will not execute until the SAVE or REFRESH is done. This is only in table format. If the display format is form, our primary key LOV's work fine. In 10g, this functionality worked fine as long as we didn't use an "ADD ROW" button on a table format. The Add Row button caused the primary key values to be returned to the application, but not be displayed on the screen. A refresh would then show them.
    From the initial investigation in the JHeadstart forum, I realize that we are hitting the "Primary Keys from Model" 6894412 problem that is listed in the 11.1.1.4 Release Notes. We have spent many, many hours establishing a re-usable .jar file of all of the entities of this very large database as suggested by JDeveloper Best Practises (http://download.oracle.com/docs/cd/B31017_01/web.1013/b25947/bcadvgen007.htm). This has worked very well for us in 10g - define all the entity specifics in one place, once, then every application can re-use them. Productivity at its finest. Therefore, we cannot make fake columns in our database in order to fix this "limitation" in 11g. We have many complex parent/child/child tables to put into our application which will not work unless our entities have the primary keys properly defined. I have tried to implement the workaround that was found in the release notes, but have been unable to get it to work.
    I have created a testcase with the HRSchema by adding a table to that Schema that I can provide the SQL commands for, but I do not know who in Oracle support to send it to. Could someone please provide me with the information on who to contact. I have, I believe, taken all the steps as established in the release notes for this problem and have clearly documented the changes in the .jsff page, but the problem still exists. Clearly, I am doing something wrong, or need more information.
    Thank you in advance
    Mary
    UofW

    Frank:
    I thank you for your reply.
    I have been working on the JHeadstart forums for so long, I actually forgot how to submit things to Metalink, and now that I have done it again...SR #3-3101357281 for this issue....I realize why I blocked out using Metalink from my memory.
    It took me an incredible amount of time to fill that SR in, then after completing everything, I was sent a request by the person assigned to the SR to repeat the instructions of how to run my testcase. I had already filled out all of the instructions on how to run the testcase in the "Notes to Oracle" section of the upload step. Almost every time I send something to Metalink, I have to repeat things. It seems as though they aren't read fully and any reason at all is used to send them back to the client.
    My dealings with Metalink have been very, very frustrating. My colleagues share this sentiment.
    Mary
    UofW

  • Issue with INSERT INTO, throws primary key violation error even if the target table is empty

    Hi,
    I am running a simple
    INSERT INTO Table 1 (column 1, column 2, ....., column n)
    SELECT column 1, column 2, ....., column n FROM Table 2
    Table 1 and Table 2 have same definition(schema).
    Table 1 is empty and Table 2 has all the data. Column 1 is primary key and there is NO identity column.
    This statement still throws Primary key violation error. Am clueless about this? 
    How can this happen when the target table is totally empty? 
    Chintu

    Nope thats not true
    Either you're not inserting to the right table or in the background some other trigger code is getting fired which is inserting into some table which causes a PK violation. 
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Auto_increment issue faced with primary key

    create table test(
    snum int not null auto_increment,
    course_id varchar(15),
    primary key(course_id, snum))
    create table testt(
    course_id varchar(15),
    pre_id varchar(15),
    foreign key (course_id) references test(course_id),
    foreign key (pre_id) references test(course_id))
    the above two table test has a primary key (snum, course_id) . course_id, which is being referenced in below table testt as a foreign key.
    i have an issue when trying to create a table test wit primary key (course_id, snum) that Error code 1075, SQL state 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key. but when place primary key(snum, course_id) it's working in this case i wasn't able to use course_id as foreign key for below table testt.
    could you please suggest me how to resolve this issue.

    The description of this forum is "Discussion of Oracle SQL and PL/SQL issues "
    MySQL Forums are at http://forums.mysql.com/
    Hemant K Chitale
    Edited by: Hemant K Chitale on Jan 11, 2011 2:56 PM

  • Issues mapping table with no primary key?

    As an exercise, I'm building a small application mapping a set of mySQL tables, using JPA. I have one table that does not have a primary key. I can see a workable natural composite key that will be unique in my data. Will I have any issues if I define the composite primary key in my JPA code, even though the table doesn't have a primary key defined?

    As long as the primary key do not change after the constructor is called it should work without any problem. But your select may be show without an index.

  • Issue with getting sequance number from db in EO for a primary key column

    Hello Experts,
    we are working on ADf 11.1.1.2.
    we are facing issue with sequence number in our UAT instance.
    dev instance and sit instances did not gave any issues.
    We have one EO in that for one attribute we have given the value as
    new oracle.jbo.server.SequenceImpl("XXOZF_QA_CODE_S", object.getDBTransaction())).getSequenceNumber()
    in order to get the primary key column value from db sequance .
    <TransientExpression><![CDATA[(
    new oracle.jbo.server.SequenceImpl("XXOZF_QA_CODE_S", object.getDBTransaction())).getSequenceNumber()
    ]]></TransientExpression>
    now the issue is "I have incremented the sequence number through SQL plus from 10 to 20. And created a record on a VO which is based on above EO.
    But the sequence iam getting is 11 instead of 21."
    This is happening only in our uat instance all other instances are working fine.
    Can any one tell us how this frame work is still pointing tho the old sequnce number.
    regards
    Gayaz

    Also make sure that your sequence has NOCYCLE option.
    some thing like this:
    CREATE SEQUENCE test_seq
    START WITH 1
    INCREMENT BY 1
    NOCACHE
    NOCYCLE;

  • Primary Key Multiple Column with Date - parameter issue

    All,
    I am having an issue that I cannot find the answer to. I have looked high and low to no avail. Please help.
    The issue at hand is that I have a table that has a multiple column primary key and one of the columns happens to be a date and the other is a string. I have a basic search and I want an update picture in the results table that the users can click on and go to a different page to update that record. The issue is when I fire an action based on the update picture I also want to set parameters based on the record that I selected. So I set the string parameter and that works fine. The issue is with the date. When i set the date parameter it works but it chops off the timestamp. Later when I try to get this parameter 'pageContext.getParameter("dateParameter");' it will bring in a date like 15-Dec-2008 but I need the entire date and timestamp (i.e. 15-Dec-2008 10:20:33) to correctly identify the record.
    Please help!
    Thanks,
    Colby J

    Hi
    since every parameter go in url as a string format so u will never get the date parameter with complete timestamp,the solution would de
    1.) Set a fire action on update picture,give its event name as "update",
    2.) clicking on update picture will fire this event .
    3.) in processFormrequest method of controller
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if ("update".equals(pageContext.getParameter("event")))
    // this will give the select row where update is clicked
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    VORowImpl row = (EmployeeSummaryVORowImpl)am.findRowByRef(rowReference);
    Timestamp sdateVal=(String)row.getAttribute("Date value");
    // this will transfer the values to next page
    pageContext.putTransactionTransientValue("transferdvalue",sdateVal);
    // and in the next page u can get the value like this
    timestamp getDateVal=pageContext.getTransactionTransientValue("transferdvalue"l);
    hope this will resolve your issue,Please let me know if u face any issue
    thanx
    Pratap

  • Issues while changing primary key in table

    Hi
    I have one table. In that two fields are primary key. I want to change the second PK as FK only. But when i am changing this field as FK. Its showing one error 'Primary Key Change not permitted for value Table ZCAUSECATMASTER' . How to avoid this error.
    Please help me.

    Hi.....
    Remove that primary key for the second field and assign your foregin key..table to that filed.....
    So when you give entries in that second filed it will be validated with its foregin key table......its nothing but check table...
    what all values in the foregin table only can given.....
    regards
    raja

  • Inner join-select -primary key in table issue

    Hi ,
            Iam using FEBKO(header) and FEBEP(item) in inner join  select .But the datas fetching by this selct in not correct.The analysis is the is no common primary fields in the both table.
    Question 1-> Can i use inner join without common primary key in the both tables, weather it possible to make a select without common primary key in both table. Please kindly let me know.
    Question 2-> What is the other possible way to give the selct for both table(better performance)
    Regards,
    Veera

    Hi,
    When you use INNER JOIN in this case, link your tables based on KUKEY and ESNUM fields, bcoz there can be many items under a single header. So this will work for you, even from the performance point of view.
    Hope this is helpful to you. If you need further information, revert back.
    Reward all the helpful answers.
    Regards
    Nagaraj T

  • Primary key vs Secondary key - why would a rpt hit one as to the other?

    Post Author: kevans
    CA Forum: Data Connectivity and SQL
    Here's an issue that surfaced when using CRW10, happens with XI as well, but not an issue with CRW8 - each one is hitting the same SQL Server db.
    I discovered something today and I'm not sure if this might be the road to a solution, however, I don't know enough about SQL Server and/or Crystal.  First, my reports seem fairly simple in nature, I don't think I'm pulling a million rows of data, maybe but doubt it.  So I run report ABC and I see blocking issues in SQL Server Enterprise Mgr.  If I run report XYZ that isn't too much different than ABC, I do not see blocking issues.  Hmm, what could be different?  In SQL-Mgr when I look at the SPID info generated by the report I can see the tables the report is referencing and below is what I discovered.
    The one difference I see is under the "Index" column - the report blocking shows "XPKcall_req" where call_req is the table I'm pulling from.  The report that IS NOT blocking shows call_req_x0.  I checked with our dba and he wasn't sure, other than to say XPK is the primary key index.  Okay, then why is one report hitting the primary key index (whatever that is) and the other isn't?  In Crystal I'm not sure how to tell it to stop doing this, I tried shaking my finger and yelling but like my kids this does little.
    Any ideas, with the report that is?

    Post Author: kevans
    CA Forum: Data Connectivity and SQL
    Here's an issue that surfaced when using CRW10, happens with XI as well, but not an issue with CRW8 - each one is hitting the same SQL Server db.
    I discovered something today and I'm not sure if this might be the road to a solution, however, I don't know enough about SQL Server and/or Crystal.  First, my reports seem fairly simple in nature, I don't think I'm pulling a million rows of data, maybe but doubt it.  So I run report ABC and I see blocking issues in SQL Server Enterprise Mgr.  If I run report XYZ that isn't too much different than ABC, I do not see blocking issues.  Hmm, what could be different?  In SQL-Mgr when I look at the SPID info generated by the report I can see the tables the report is referencing and below is what I discovered.
    The one difference I see is under the "Index" column - the report blocking shows "XPKcall_req" where call_req is the table I'm pulling from.  The report that IS NOT blocking shows call_req_x0.  I checked with our dba and he wasn't sure, other than to say XPK is the primary key index.  Okay, then why is one report hitting the primary key index (whatever that is) and the other isn't?  In Crystal I'm not sure how to tell it to stop doing this, I tried shaking my finger and yelling but like my kids this does little.
    Any ideas, with the report that is?

Maybe you are looking for

  • Is there a way to upload Photos to iCloud in small groups

    The new Photos app is causing havoc with our home Internet. It seems to be hanging up and working, if at all, very slowly. Apple Support didn't seem to see a problem. But when the upload to iCloud option is turned on, our home Internet speed goes fro

  • No Signal

    OS Name Microsoft Windows 7 Professional Version 6.1.7601 Service Pack 1 Build 7601 System Model h8-1090t System Type x64-based PC Processor Intel(R) Core(TM) i7 CPU 970 @ 3.20GHz AMD Radeon HD 6850        A few days ago I was working on my computer

  • Interfaces, Abstract Classes & Polymorphism

    I have a friend taking a Java course as part of a larger degree program, and she's asked for some help with an assignment. The assignment is as follows: This assignment is to write a simple encryption/decryption application.  There will be a single a

  • Is it possible to have undefined attributes for an item type...see more in the messag

    I want to create an item called 'book' with attributes like title, date of publish, language, pages....and author, but i want that users can assign many authors (as much as users want)....is this possible?? How can I realize it??? Could I create auth

  • "Tell a Friend" not working in Aperture 3

    After publishing new galleries using MobileMe, the option to "Tell a Friend" does not work. It used to work fine in previous versions of Aperture, but now nothing happens. Using the email option to send a photo works fine. Has anyone else come across