Auto Increment of primary key value in jdeveloper.

hi all,
i have one table with one primary key.
i want to increment that primary key when ever i go for CreateInsert or create operation in JSF page.
i have tried with db sequence value type, but i was not able to achieve my condition. in DB Sequence i got error like cannot convert java.class.string to java.class.dbsequence.
can any one suggest me in this to achieve my condition.
regards,
M vijayalakshmi.

hi all,
from this i found the simple method to achive the auto increment of primary key.
http://www.techartifact.com/blogs/2012/10/adding-number-for-primary-key-in-oracle-adf-using-groovy-by-sequence.html#ixzz2EeU9CWo6
in this am facing an one small issue.
intial value of the primary key is 1.
for this value i have entered the row of data.
again i have clicked on the create button.
then the value of the primary key has increased to 2.
for this value i didnt entered the row of data to databse.
just i closed the browser.
if i run the run page again, the value of primary key is 3.
my requirment is i shd get the value of primary key is "2".
the increment shd happen the maxi value present in the primary key of the table.
can any one help me in this how to achive this.
thanks in advance.
regards,
M vijayalakshmi.

Similar Messages

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • EJB3: One-to-one relationships and auto-generation of primary key values...

    Dear Forum,
    I'm relatively new to JEE, and while I've so far enjoyed the convenience of EJB3 for most things, it seems that I have a corner case that can not be handled by the entity manager.
    First, here's a quick mockup of my entities:
        Gallery
                |
                -- [1] -------[1] ----> Author
                |
                -- [1] -------[M] ---> Photo
                                                  |
                                                  -- [1] ------ [1] -> PhotoImage
                                                                                     |
                                                                                     -- [1] ------ [1] -> IPTCData
                                                                                     |
                                                                                     -- [1] ------ [1] -> EXIFDataI also have a remote, stateless session bean that does nothing more than persist()/merge()/remove() and locate (through find() and a few custom queries) my Gallery and Photo instances.
    Now, the abridged version of my problem is this: when I persist a Photo, it naturally gets its primary key generated (I used @Id and @GeneratedValue). However, for some reason none of the other dependent entities inherit Photo's primary key value. In my client, I create a new Gallery locally and then persist it. I then create new Photo, PhotoImage, IPTCData and EXIFData instances. I add the IPTCData and EXIFData instances to PhotoImage (there are PhotoImage methods for adding those); then I add the PhotoImage instance to Photo (again, Photo has a setter for adding a PhotoImage). Then, I persist the Photo.
    --- Aside: ------------
    I've set up my relationships using annotations like @OneToMany (Gallery references a Collection of Photos), and @OneToOne (Photo's primary key references PhotoImage's primary key; PhotoImage's primary key references the primary keys of IPTCData and EXIFData). I've also added @JoinColumn annotations where necessary.
    Finally, I get the Gallery instance's Photo collection (public Collection<Photo> getPhotos()), I add the Photo to the collection, and I add the Photo collection BACK to the Gallery (public void setPhotos(Collection<Photo>)).
    At this point, the Gallery should have all of my entities contained inside of itself. However, when I persist the Gallery at this point, all of the entities show up in the database, but none of the primary keys get inherited. Photo's primary key gets generated automatically, of course, but the rest have zero (0) as their PK values. I had wanted, for example, IPTCData to get the value of Photo.id.
    I had assumed that the entity manager would persist everything for me provided that I told it, through my annotations, about which entities relate to which. Does persistence only work in the direction of retrieval? That is, does the entity manager only do its thing when fetching (versus setting) data when there is more than 1 object in the graph? I can't believe that it can't, otherwise we'd all be ditching it and going back to straight SQL to do our work.
    Thus, I HAVE to be doing something wrong, or else omitting to do something right.
    I've made other incarnations of the above setup, and none of them have worked perfectly. I've even set up foreign key constraints in the database, but I had my share of unresolvable problems there, too.
    So I guess my big question with all of this is: when you have a deeply nested graph of objects, can the entity manager figure everything out and persist all of the objects correctly and with the right values? If not, boo. If so, how does one accomplish this?
    I know that I could persist each and every entity separately in my client code, but I wanted to have a natural-looking way of piecing all of my entities together. More specifically, I could persist IPTCData explicitly; however, I want to be able to add everything to a Photo and only persist the Photo itself, with the idea that all of the objects and sub-objects would be persisted automagically.
    Is this possible? Or have I bought into a pipe dream with the guarantee of the proverbial magic bullet?
    Thanks to everyone in advance for his/her input.
    Regards,
    Michael

    Daniel,
    Late last night I found the solution to my problem. And you're right, it had everything to do with which side is wired to which. I got confused about which side to consider the "owning" side, since one can look at it from the perspective of the database or the application.
    Interestingly, the first 2 lines of your example code match my client code almost verbatim: First, I create a new Gallery (or else I get an existing one). I then create a new Photo and then add it to the Gallery's collection using add(). I then persist the Gallery. My session bean internally calls EntityManager.merge(gallery). How it differs from your example, though, is in the fact that, on an application level, a Photo has no knowledge whatsoever of a Gallery. Which is to say that my Photo class does not have a 'getGallery()' method. Somehow, Hibernate is able to figure it all out and still update Photo's 'parentIdRef' column in the database. My logs show that Hibernate issues a SQL UPDATE on the Photo after both a Gallery and a Photo have been created. It sets the Photo's 'parentIdRef' column to the primary key value of the owning Gallery.
    Getting back to the matter, my problem was not with being able to map a Photo to a Gallery; rather, I was unable to add a PhotoImage to a Photo and have the relationship get correctly mapped in the database. The relationship between a Photo and a Gallery is many-to-one: there can be many Photo objects inside of a Gallery. In the database, a Photo row contains a 'parentIdRef' column whose value is that of a Gallery's primary key. I used @OneToMany on the Gallery, since a Gallery is, from an application perspective, the "owning" side, even though it's only the Photo that knows who it's referring to since only IT contains the 'parentIdRef' column in the database.
    I tried setting up the relationship between a PhotoImage and a Photo in the same manner, with the PhotoImage having a 'parentIdRef' column and referring to a Photo's primary key. I had annotated the Photo's getPhotoImage() method with @OneToOne, along with an appropriate @JoinColumn.
    It was THIS part that I had backwards. With a @OneToMany relationship, the child refers back to the parent --- it can be no other way. However, with a @OneToOne relationship, the owner refers to the child.
    So, to make a long story short, all I had to do was create extra database columns for Photo. Those columns refer to the primary keys of PhotoImage, EXIFData and IPTCData. Concretely, for example, Photo.photoImageIdRef references PhotoImage.id. And so on and so forth.
    The only negative side-effect of this is that my database-level foreign key constraints are now broken, since Hibernate wants to persist PhotoImage, EXIFData and IPTCData before it persists Photo.
    I have to investigate more deeply the 'cascade=...' option of the @OneToOne annotation in order to find out it relates, if at all, to a database-level cascade.
    Anyway, thanks for the reply. It seems that you had a very good idea about what my problem was. I would have posted the fact that I had resolved the problem last night, except that it was too late and I was heading to bed. If you still want the Duke points, let me know. I don't currently know the rules about if, when and to whom I should issue points in cases like these when I've already solved the problem.
    Regards,
    Michael

  • Auto generate the primary key value for eah valid insertion

    i have a table EMP having emp_id, name and age.
    EMP;
    E1 John 23
    E2 Mary 25
    created a form/report page on the table. the report page displays all the columns. while creating new entry, the emp_is hidden and the name , age are displayed. on successful insertion the emp_id is populated with 1 rather then E3.
    1 Rick 22
    E1 John 23
    E2 Mary 25
    how do i ensure that the new row inserted has a value E3 and the subsequent entries, emp_id is incremented by next sequence.

    If your emp_id is not numeric and needs to be 'E' + sequence then you need to delete the existing trigger and create a new one like this:
    CREATE OR REPLACE TRIGGER emp_bi_trg
       BEFORE INSERT
       ON emp
       FOR EACH ROW
    BEGIN
       IF :NEW.emp_id IS NULL
       THEN
          SELECT 'E' || emp_seq.NEXTVAL
            INTO :NEW.emp_id
            FROM DUAL;
       END IF;
    END;
    /Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------

  • Apex Form - how to enter primary key value manually?

    Hi
    Whenever I am creating Apex form using wizard, it asks me to specify trigger/sequence/pl/sql function for populating primary key value.
    However, if I want to specify primary key myself (ie. not auto generated number), how I can specify that?
    Thanx

    Hello,
    By Yourself you mean : by hand or by a pl/sql?
    If you say by trigger, the system doesn't care about what number is send. So you can give it "manually"
    May I ask what is the reason of that?
    Cheers,
    Arnaud

  • How can we export the Primary key values (along with other data) from an Advantage database?

    One of our customers is moving from our application (which uses Advantage Database Server) to another application (which uses other database technology). They have asked us to help export their data, so that they can migrate it to another database system. So far, we have used the Advantage Data Architect (ARC32) "Export Table Structures as Code" functionality to generate SQL. We used the "Include existing data" option. The SQL contains the necessary code to recreate the tables and indexes. The customer's IT staff will alter the SQL statements as necessary for their new system.
    However, there is an issue with the Primary Keys in these table. The resulting INSERT statements use AutoInc as the type for the Primary Key in each Table. These INSERT statements contains "DEFAULT" for the value of each of these AutoInc fields. The customer would like to output an integer value for each of these Primary Key values in order to maintain referential integrity in their new system.
    So far, I have not found any feature of ARC32 that allows us to export the Primary Key values. We had been using an older version of ARC32, since our application does not use the latest version of ADS. I did download the latest version of ARC32 (11.10), but it does not appear to include any new functionality that would facilitate doing this sort of export.
    Can somebody tell me if there is such a feature in ARC32?
    Or, is there is another Advantage tool to facilitate what we are trying to accomplish?
    If there are no Advantage tools to provide such functionality, what else would you suggest?

    George,
      It sounds like the approach you are using is the correct one. This seems to be the cleanest solution to me especially since the customer is able to modify the generated SQL statements for their new system.
      In order to preserve the AutoInc values I would recommend altering the table and changing the field datatype from AutoInc to Integer. Then export the table as code which will export the actual values. After the tables have been created on the new system they can change the field datatype back to an AutoInc type if necessary.
    Regards,
    Chris Franz

  • Display the second report as modalform and filter with primary key value of first report when you click on first report column link

    Hi All,
    I have two reports.
    1. order report
    2. order detail report
    when you click on the order report column it display the order detail report as a modal form.
    i was done below steps.
    1. In page header i was written the below code
    <link rel="stylesheet" href = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/
    redmond/jquery-ui.css" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"> </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"> </script>
    <script type="text/javascript">
    $( function() {
    $('#ModalForm1').dialog(
    autoOpen : false ,
    width :470,
    height: 500,
    resize :false,
    function openForm1()
    $('#ModalForm1').dialog('open');
    function closeForm()
    $('#ModalForm1 input[type="text"]').val('');
    $('#ModalForm1').dialog('close');
    </script>
    2. order report.
    3. order detail report
       select * from order_details where order_id = p_order_id;
    region header
    <div id="ModalForm1" title="Ordered Items" style="display:none">
    <p class="msg"></p>
    footer
    </div>
    4. created the hidden item in order detail report.
    5. in order report column attributes i was given link like below.
    javascript:$s('p_order_id','#order_id#');openForm1();
    when i click on the order report column link it passing the row primary key value to hiddent and open the report as modal form. however it is not filter the report with hidden item. it showing the no data found.
    problem is hidden item value is not submitting. once we submit that value it showing the 2nd report with filter data.
    can any help me to achieve above requirement.
    apex: 4.2
    oracle 11g
    Regards,
    Vijay.

    Vijay,
    Issue 1: Your usage of $s() JavaScript API seems to be wrong. For the first parameter, you need to use the name of the hidden page item and not p_order_id.
    javascript:$s('P1_ORDER_ID','#ORDER_ID#');openForm1();
    Issue 2: Seems like you are not setting the hidden page item's value in session state. Assuming your hidden page item is called P1_ORDER_ID, Under "Region Definition" tab of your "Order Detail Report" under "Source" tab, for page items to submit, enter the name of the hidden page item P1_ORDER_ID.
    Thanks!
    JMcG

  • Validation on Primary Key value in TMG

    Hi,
    I have a  custom table with field Outcome_id as primary key. I have to put some validation on this primary key value.
    For the above I hv used a TMG Event '01' and written the code for validating the values.
    On save when validation fails the primary key field gets disabled even though entry is prevented from being saved.Since the value of the primary key cannot be changed the validation fails recursively.
    How cn I keep the primary key fields enabled when the validation fail.
    Rgds,
    Swati.

    Hi,
    As per basic Module pool programming a screen field gets disabled after throwing an error.
    You will have to use Field statement in the module pool program generated for your tables TMG and modify it.
    But please note- any time TMG is regenerated all changes are lost.
    "refering sap help "
    Checking Single FieldsIf you send a warning or error message from a module mod  that you called using a FIELDstatement as follows:
    FIELD f MODULE mod.
    the corresponding input field on the current screen is made ready for input again, allowing the user to enter a new value. If the field is only checked once, the PAI processing continues directly after the FIELDstatement, and the preceding modules are not called again.
    refer this :
    [http://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbaa4735c111d1829f0000e829fbfe/content.htm]
    Edited by: sap_wiz on Jun 22, 2011 5:20 PM

  • Creating a New Row Using an ADF Iterator Binding without primary key value

    I dropped a Create action onto a DataAction which forwards to a UIX entry page which contains an enabled Commit button. Part of the primary key value is held in a session bean and it is also current in another view on the model side, but I am unable to access this value to set the EntityImpl primary key attribute.
    Upon submission the following error message is returned from the model:
    ORA-01400: cannot insert NULL into ("GTR"."EMPLOYMENT"."ACCOUNT")
    I would like to accomplish this with databinding and not create a custom create method on the application model. Is there a way to update the binding value for the new row in cache before the submission? Any advice would be welcome.

    I should add that I want the user to enter every attribute value, except for the account number. It must be possible to create a new row and have the account number supplied to the bindings another way.

  • How to Create process of Type : Get Next or Previous Primary Key Value

    Hi,
    Can anybody give the steps how to create the page process for type Get Next or Previous Primary Key Value in oracle Express database
    Ramesh j c.

    Hi Justin,
    In oracle 10g XE , we have sample application v2.0
    1. Do you have any Document to create step by step the sample application v2.0 and Is it possible to create all the pages of this sample application v2.0 b by wizard. To recreate or create the demo app, start from the home area,
    next go to application builder,
    then click the create button,
    next choose "demonstration application"
    and then you can choose "Run | Edit | Re-install" the "Sample Application" along with a few other apps.
    2. When we install this sample application v2.0 , which is the sql script is executed or how it is installed. If you want the sample application you can export it after you create it if you want the SQL associated with it.
    3. Whenever the sample application v2.0 is installed, how the encrypted pass word is created for the user demo and admin. This is setup with the application install. I don't believe it is encrypted either. If your wanting SSL there are some threads on here that talk about encrypting content.
    Justin thanks for to create process Get Next or Previous Primary Key Value

  • Chaging primary key value when child record present

    Please tell me how to change the primary key value when it's child record is present.

    Well something like INSERT new primary key, UPDATE child records, DELETE old primary key would seem fairly obvious.
    Using deferrable constraints may make the process rather simpler.
    If on the other hand you are looking for UPDATE cascade functionality, Tom Kyte has an article regarding implementing this.
    http://asktom.oracle.com/tkyte/update_cascade/index.html

  • ?Trigger to return primary key value after insert"

    Ok, so I'm a newbie to oracle. I was hoping someone could tell
    me how I can get the value of a field after insertion. I
    created a sequence and a trigger to autoincrement the primary
    key. I figured out that select @@Identity does not work. So
    I'm trying to figure out how to return the primary key value of
    just inserted record.
    Any help or suggestions would be really appreciated.
    thanks matt

    I have 3 tables - master, detail and collector.
    when a record is inserted into the collector table - I want to fire a trigger and insert the value of "collector.a_test", "collector.b_test" into "master.test" and "detail.test" respectively.
    I want to create an after/insert trigger on the collector table to accomplish this. I tried to implement the example listed in previous message (see below) *** BUT **** I get a PLS-00103 error - "Encountered the symbol "A_ID" when expecting one of the following: :=. ( @ %;
    Note: master, detail and collector have before insert trigger/sequence that assigns their PK values.
    master has 2 columns - a_id (number PK), a_test (varchar2(255))
    detail has 3 columns - b_id (number PK), b_test (varchar2(255)), aa_id (number FK)
    collector has 3 columns - c_id (number PK), a_test (varchar2(255)), b_test (varchar2(255))
    as in;
    create or replace trigger wf.c_a_b_insert
    after insert on wf.collector
    referencing old as old new as new
    for each row
    declare
    aa_id master.a_id%type;
    begin
    insert into master (a_test) values(:new.a_test);
    returning a_id into aa_id;
    /* now insert into detail and get the FK value from aa_id */
    end;
    What am I doing wrong and how can I fix this?
    Thanks much!
    Bill G...

  • Need to get primary key value from entity

    Hi,
    I have 2 pages. In the first page on click of GO button, Im inserting data into table using EO and Immediately navigating to second page.
    Primary Key value is generated in EOImpl java file.
    In second screen, in the header region, I need to show the row inserted in table.
    to query the VO, i need to have primary key generated in EOImpl.
    Please let me know how can i get this value in either in PFR of first page or in PR of second page. Thanks.

    Hi
    have you included the eo that tyou are refering to in the header oif the second page..
    if both pages are using the same AM, the data will appear.
    at worse can you can get the ID from the eo using amethod in your AM.

  • How to update a parent (primary key) value?

    hello...can anybody give me a hint that how to update a primary key value in master table through forms as well as update all child records keeping in mind that "ALTER TABLE" and constraint disabling is not permitted by DBA. Parent Records are being displayed in form in a database block while child records are not displayed on form.

    See
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:914629004506
    and
    http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteupdatecascade.html
    cheers

  • Auto Increment of Primary Field in Table Maintainance

    Hi,
    We want to give an Auto increment to the Primary Key, when ever the table is updated/inserted with a new record. How to get the value updated????
    For Eg,
    Table ZTEST Contains     MANDT, ITEM,   EBELN.
    It should have the values 800    001   000977
    And when the next record is created, the ITEM value should be Automatically get the value 002.. and so on for every Record.
    Pls do let me know if any other details is reqd.
    Thanx in Advance.
    Ajaz

    Dear Syed,
       You can do many things in table maintenance screen like validation of some field, making some field required or displayed etc.
       For auto increment you have to use Number-Ranges. FM NUMBER_GET_NEXT is helpful in this case.
       Where to write the code??? The Function-Group you have made. There will be includes. You can easily locate the place to write these codes.
       Caution point is that if you re-generate the table maintenance then all code will be gone.
    Regards,
    Deva.

Maybe you are looking for

  • Overset Text In InDesign

    I've created a wall calendar in InDesign.  In preflight, there are 80 errors, all overset text.  Does this mean that the overset text just won't show up in print?  Because if that's the case, I don't need it anyway.  So would I need to delete it or d

  • HP Compaq d330 uT d330m/P2.8C/40bc/128F/4

    Dear Sirs, We are getting message INPUT NOT SUPPORTED on the display Kindly advice why we are getting message INPUT NOT SUPPORTED, IN CASE IT IS IS BECAUSE OF DRIVER FOR VIDEO, request to let us have the driver S/N of CPU[edited by Moderator], P/N  P

  • Upgraded to Leopard - What About Bootcamp?

    I just upgraded to Leopard and was wondering what I need to do, if anything, to my existing Bootcamp setup? I'm running XP Pro and was curious if I had to make a new driver CD or anything like that. Thanks.

  • Can I attend Oracle 10g DBA course & attempt DBA Certification for 11g

    Hi, I am already OCP-PLSQL and want to attempt OCP-DBA stream. I enquired at various oracle education centers and came to know that all are conducting courses for Oracle-10g. So can I attend Oracle 10g DBA course (Mandatory Course) and attempt DBA Ce

  • If I learn on Logic Pro 9, will it be difficult to move to Logic Pro X?

    Hello, I am studying Logic Pro for composition of orchestral music - I bought Logic Pro 9 about 2 months ago, as I had no idea Logic Pro X was coming out. I also purchased a couple of books to study it. I am not complaining about the lack of upgrades