How to use Oracle DB Sequence to Generate Primary Key Values?

Dear Members,
I am using Oracle JDev V 11.1.2.1.0 and Oracle 11g XE Database.
I have followed the below steps:-
1/ Created an EmployeesEO
2/ Created an EmployeesVO
3/ Created a JSPX Page
4/ On the JSPX Page I have dragged the EmployeesVO and created it in ADF Table Format.
On this page when I create a new record, I want to generate employee id automatically based on a sequence which is created in the database of the HR Schema.
Please let me know how to achieve the above requirement.
Many thanks in advance.
Regards.

check [url http://mjabr.wordpress.com/2011/03/11/make-sequence-number-as-default-value/]Set an attribute’s default value with a sequence number

Similar Messages

  • 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.

  • 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

  • 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.

  • Using oracle db sequence for auto generating of PKs for CMP entity beans

    Hi,
    I have read quite a number of threads about (auto) generation of keys for primary keys for the CMP entity beans.
    My requirement is I am migrating an application deployed on Weblogic to oc4j. The application is using cmp entity beans with auto key generation using a sequence in the Oracle db. This is specified in weblogic-cmp-rdbms-jar.xml file like below:
    <automatic-key-generation>
    <generator-type>Oracle</generator-type>
    <generator-name>REPUSER.DEPT_REPORT_SEQ</generator-name>
    <key-cache-size>1</key-cache-size>
    </automatic-key-generation>
    In the ejb-jar.xml, it is specified as:
    <prim-key-class>java.lang.Integer</prim-key-class>
    <primkey-field>id</primkey-field>
    Now, I need to migrate this to oc4j. Can somebody suggest me options and clarify my questions kindly?
    1) I have read articles that say that in the ejb-jar.xml, we need to specify <prim-key-class>java.lang.Object</prim-key-class> and this will create a column called 'autoid' in the respective entity table in the Oracle db.
    - How can I use this to assign the value to my primary field, say, id?
    2) Now, with the latest oc4j, can I use Oracle database sequence as the key generator for the values of the PKs just by specifying in the xml descriptor ejb-jar.xml?
    2.a) If yes, is there any article that explains with the code?
    2.b) If no, what are the alternatives I have?
    I have read many discussions that say that we can create a stateless session bean that can lookup the database sequence using simple JDBC call to return the nextval of the sequence. The SSB should be called in the ejbCreate() of the entity bean.
    My related question is, what is recommended for oc4j? What are limitations of the various options for the latest oc4j available?
    How should I go about deploying this kind of ejbs in oc4j?
    Any help and pointers are welcome. Please help.
    Thanks a lot.
    Vadi

    Hello ,
    Instead of exposing a get/set method for each arribute of your bean (corresponding to database table) expose only one object.
    For example
    public class CustomerBean implements javax.ejb.EntityBean{
    private CustomerVO objCustomer;
    private String customerName;
    private String customerMail;
    private String customerType;
    public CustomerVO getCustomer(){
    return this.objCustomer;
    public void setCustomer(CustomerVO objCustomer){
    this.objCustomer = objCustomer;
    public void ejbStore(){
    customerName = objCustomer.getName();
    customerMail = objCustomer.getMail();
    customerType = objCustomer.getType();
    HTH
    VJ

  • Use oracle native sequence

    How one can use oracle native sequence in Insert/update in a Toplink POJO?
    Thanks in advance...

    Just set the Oracle Sequence name as the descriptor's sequence name (ClassDescriptor.setSequenceName()), and configure your Session to use native sequencing.
    If you are using JPA you need to use a @SequenceGenerator see,
    http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Sequence_objects
    James : http://www.eclipselink.org

  • How to use oracle fusion middleware for integration project ?

    hi all,
    in my projects, customer (a bank) already has many applications (bankend & frontend) that are complicatedly connected. I intend to use oracle fusion middleware to integrate all applications and make adding new applications in the future easier. I have worked through documents in the oracle website but I still have no idea how to use oracle fusion middleware to address the requirement, besides oracle fusion middleware includes a bundle of applications I don't know which one I would need.
    could anyone give me some instructions ? appreciate your help.
    thank very much,

    Hi,
    For this short description of environment, could be ODI is a incredible tool to help you...
    Take a look into my blog that has a lot of concepts and "how to do" instructions.... http://odiexperts.com
    However to try help you, what are the used technologies?
    Where are you from?
    Cezar Santos
    http://odiexperts.com

  • How to use Oracle partitioning with JPA @OneToOne reference?

    Hi!
    A little bit late in the project we have realized that we need to use Oracle partitioning both for performance and admin of the data. (Partitioning by range (month) and after a year we will move the oldest month of data to an archive db)
    We have an object model with an main/root entity "Trans" with @OneToMany and @OneToOne relationships.
    How do we use Oracle partitioning on the @OneToOne relationships?
    (We'd rather not change the model as we already have millions of rows in the db.)
    On the main entity "Trans" we use: partition by range (month) on a date column.
    And on all @OneToMany we use: partition by reference (as they have a primary-foreign key relationship).
    But for the @OneToOne key for the referenced object, the key is placed in the main/source object as the example below:
    @Entity
    public class Employee {
    @Id
    @Column(name="EMP_ID")
    private long id;
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ADDRESS_ID")
    private Address address;
    EMPLOYEE (table)
    EMP_ID FIRSTNAME LASTNAME SALARY ADDRESS_ID
    1 Bob Way 50000 6
    2 Sarah Smith 60000 7
    ADDRESS (table)
    ADDRESS_ID STREET CITY PROVINCE COUNTRY P_CODE
    6 17 Bank St Ottawa ON Canada K2H7Z5
    7 22 Main St Toronto ON Canada     L5H2D5
    From the Oracle documentation: "Reference partitioning allows the partitioning of two tables related to one another by referential constraints. The partitioning key is resolved through an existing parent-child relationship, enforced by enabled and active primary key and foreign key constraints."
    How can we use "partition by reference" on @OneToOne relationsships or are there other solutions?
    Thanks for any advice.
    /Mats

    Crospost! How to use Oracle partitioning with JPA @OneToOne reference?

  • How to use Oracle refcursor dataset output parameter from SP

    Can I request for help on how to use Oracle Output parameter from a stored procedure as a source. I need the output tobe stored in a flat file
    Thanks
    Abhijit
    Message was edited by:
    Abhijit77

    yes I would like to use it for ODI.. I would like the ouput of the refcursor to be fed to a text file using ODI. How to handle the records returned by the refcursor and map with txt file.

  • How to Use Oracle 8i with MapX?

    I am trying to work with oracle 8i 1.6 and mapX 4.5 but un-able to do so. I tried by adding server layer but couldn't do so.
    Help !!

    Crossposted: Re: How to use Oracle partitioning with JPA @OneToOne reference?

  • 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

  • How to use my findTheHighest method to find the highest value in my two dim

    I am going to create a 13row by 10 colume two dimensional array.
    how to use my findTheHighest method to find the highest value in my two dimensional array.
    .When i compile this program , i got those as following;
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExce
    at TaxEvolution.findTheHighest(TaxEvolution.java:31)
    at TaxEvolutionClient.main(TaxEvolutionClient.java:25)"
    public class TaxEvolution{
    public double[][] salesTaxRates;
    public TaxEvolution()
      salesTaxRates = new double[13][10];
      fillProvinTaxRates();
    private void fillProvinTaxRates()
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          salesTaxRates[row][column]= (int)(Math.random()*5000) + 1;
    public double findTheHighest()
        double highest = salesTaxRates[0][0];
        for ( int row = 0; row <= salesTaxRates.length; row++ )
          for ( int column = 0; column <= salesTaxRates[row].length; column++ )
             if ( salesTaxRates[row][column] >= highest )
                   highest = salesTaxRates[row][column];
        return highest;   
    public double[][] arrayTaxEvolution()
      double[][] returnTaxRates = new double[13][10];
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          returnTaxRates = salesTaxRates;
      return returnTaxRates;
    public class TaxEvolutionClient{
    public static void main( String[] args ){
      TaxEvolution protaxRateList = new TaxEvolution();
      double[][] taxRateList = protaxRateList.arrayTaxEvolution();
        for ( int i = 0; i < taxRateList.length; i++ )
          for ( int j = 0; j < taxRateList[0].length; j++ )
            System.out.print( taxRateList[i][j] + "\t" );               
            System.out.print( protaxRateList.findTheHighest + "\t" );
    }

    Multiposted
    http://forum.java.sun.com/thread.jspa?threadID=699057&tstart=0

  • How to code the ejbCreate() method without initailizing primary key?

    Hi all,
    I've just started learning about EJBs, and now am at the stage of learning how to create, deploy and test a CMP Entity Bean.
    Ran into a problem which I'm hoping someone can help out with.
    I'm using SQL Server 2000 as my backend database, and have created a simple table called TEST with 2 fields, id and name. id is set as the primary key, and as an identity conlumn. What this means is that when we do inserts, we don't need to specify a value for the id column. SQL Servers automatically generates that value.
    Here's my ejbCreate method in my bean class:
    public Integer ejbCreate(String name) throws CreateException {
        this.setName(name);
    }When I tried to run the create method from a web client, I got this error:
    javax.ejb.CreateException: [EJB:010148]In EJB 'SampleEJB', the primary key field 'id' was not set during ejbCreate. All primary key fields must be initialized during ejbCreate. at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:186) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244) at everbright.ejb.SampleEJB_uzc4wg_HomeImpl_813_WLStub.create(Unknown Source) at jsp_servlet.__index._jspService(__index.java:152) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
    So it seems like I can't leave the id field uninitialized in the ejbCreate method. However I don't know what to initialize it with either, because in order to know what value I need to initialize it to, I'll need to run a db query to retrieve the next primary key value for the id field. This doesn't sound very efficient to me.
    I tried to initailize it to null, but that gave me a NullPointerException.
    Why do we need to initialize the primary key field in ejbCreate? Should the container do the insert and then get it from the table accordingly?
    Is there any other way I can get this set-up working?
    Thanks!

    Hi Fusion777,
    Ya, I've been searching around forums for an answer also. Apparently this is indeed a problem that has no general solution. It depends on 2 factors:
    1) Whether or not the database supports autogenerate key (which most does) and how (Oracle does it by sequences while SQL Server by identities)
    2) Whether or not the application server supports 1).
    In my case, I'm using SQL Server and Weblogic Server 8.1 and most fortunately, Weblogic does support identities and sequences. Just define the <auto-key-generation> stanza in your weblogic-cmp-rdbms-jar.xml deployment descriptor, as follows:
    <automatic-key-generation>
         <generator-type>ORACLE</generator-type>
         <generator-name>test_sequence</generator-name>
         <key-cache-size>10</key-cache-size>
    </automatic-key-generation>
    <automatic-key-generation>
         <generator-type>SQL-SERVER</generator-type>
    </automatic-key-generation>
    <automatic-key-generation>
         <generator-type>NAMED_SEQUENCE_TABLE</generator-type>
         <generator-name>MY_SEQUENCE_TABLE_NAME</generator-name>
         <key-cache-size>100</key-cache-size>
    </automatic-key-generation>I've tried that and it works :-)
    I gather from your reply that those who are using JBoss are equally fortunate :-)
    So I thought I'll share this in case some other poor fellow is facing the same problem as we are. At least worse come to worse, he'll have the option of switching to either JBoss or Weblogic and know that it works in both :-)
    Some other users seem to be against the idea of using auto-generated keys for precisely the reason that it is not a standard across database and application servers. See this thread:
    http://forum.java.sun.com/thread.jspa?forumID=13&threadID=329896
    I've in fact stopped working on EJB 2.0 and am exploring something called Hibernate, which seems to have a more generic way of dealing with the auto-generated key issue. In fact, I've heard news that EJB 3.0, which is the upcoming standard for EJB, will be heavily inspired by Hibernate as far as CMP Entity Beans are concerned.
    You can check out Hibernate at http://www.hibernate.org.

  • 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

Maybe you are looking for

  • Need to get a report from SAP on leave request data

    Hi I have a specific requirement that I hope somebody might be able to help me with in SAP. We use PTARQ tcode to see various requests that employees have submitted in ESS (statuse can be where request has just been sent, approved, posted) etc. I am

  • User Data Source in GRC AC 10

    Dear Experts, Need clariofcation regarding User data Source for SAP GRC AC . Till GRC AC 5.3 we can use only one sap backend system as user data source for gettting users like manager,approver etc and have to change User data source if user reside in

  • "Try Selecting a Different Printer or File Type" Error - iPad2 - Officejet Pro 8600 - ePrint error

    Greetings... I just got an Officejet Pro 8600 and I've been trying to get web pages to print using HP ePrint from my iPad 2 (iOS 7.0.6). I go into the ePrint app, go to web page of choice, and then click on my printer option to print. It renders on s

  • I am missing the os 10.4 disks for an early white intel imac.

    I am missing the os 10.4 disks for an early white intel 24" imac. Is there any where to download it. I have 10.4 disks for an mac pro 10.4 and macbook pro 10.4 and tons of others but am missing the install discs for this computer. Avid Xpress is used

  • Rule to open mailbox containing unread mail?

    I had been using Eudora, but have recently switched to Mail. When I used Eudora, it would open a destination mailbox when new mail was filtered to it. Is there a way that I can do this with Mail, either using rules or apple script?  Othewise it's ver