JDO Auto Generate Primary Key

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

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

Similar Messages

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

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

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

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

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

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

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

  • 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

  • Generate  primary key automatically

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

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

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

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

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

  • HOW TO GET AUTO GENERATED PRIMARY ID KEY BACK FROM AN INSERT STATEMENT IN .

    Just recently I ran into a problem with what seems to be a deficiency in the Oracle Database. When trying to return an auto-generated key as is done in Microsoft's SQL database, it seems Oracle for whatever reason didn't add this capability, the key couldn't be passed back to the .Net call. After tinkering with the .Net software and talking with the Oracle techs, a decent work around to the problem (presented here) comes fairly close. Two things have to be done first before this will work. A sequence has to be created on the Oracle DB. Also a trigger has to be created against the table the keys are going to be returned from.
    The class works by passing to the function 'update_datasets_return' a DataSet with as many tables as you want. The function spins through the tables and put the keys in each row inserted. It's assumed the first row will either be the primary key or some numeric value. This can be changed by modifying the: dt.Columns(0).ColumnName
    Notice the word Inserted. On Updates and Deletes the key value is ignored because it's already present. The routine just updates the database as usual.
    So in other words you could send a table to the function with rows inserted, deleted, or updated and it will take care of them all. One routine for all.
    ' ======================================================================
    ' Created by SEF and Oracle SR: 5607364.993 This is a complete Redo
    ' of the initial concept. SEF...
    ' Sample of sequence and trigger at bottom.
    ' Uses the ODP.NET data provider.
    ' update_datasets_return: Goes thru each table in the dataset and
    ' updates, deletes, or inserts as needed.
    ' If inserting, a 'sequence counter' and a 'trigger'
    ' using the 'before insert' must be present. The sequence
    ' counter is set to auto increment by 1 starting at 1.
    ' The trigger is specific to the table.
    ' Create the trigger and sequence in the database or run the samples
    ' below in PL/SQL. Be sure the logon with a user that has enough rights.
    ' Routine assumes the first column is going to hold the sequence
    ' number. Actually any column could be used. Just change the
    ' dt.Columns(0).ColumnName to whatever you want or leave as default.
    ' The da_RowUpdated sub is where the 'sequence number' gets returned
    ' on each row that is inserted into a table. Routine is ignored on
    ' deletes and updates. SEF...
    ' =======================================================================
    Imports System
    Imports System.Data
    Imports Oracle.DataAccess.Client
    Imports Oracle.DataAccess.Types
    Public Class OracleUpdate
    Private Shared m_conn As OracleConnection
    Private Shared da As New OracleDataAdapter
    Private Shared dt As DataTable
    Private Shared conn As New OracleConnection
    Private Shared dr As DataRow
    Private Shared astep As Long
    Private Shared rwIndex As Integer = 0
    Private Shared tblIndex As Integer = 0
    Public Shared Function update_datasets_return(ByVal constr As String, ByVal ds As DataSet) As DataSet ''ByRef ds As DataSet)
    Dim selectstmt As String
    m_conn = New OracleConnection(constr)
    Try
    m_conn.Open()
    Catch ex As Exception
    Throw New ArgumentException(" Error: connection lost." & ex.Message)
    End Try
    For Each dt In ds.Tables
    ''Uncomment the code only if auto numbering
    ''is NOT turned on for the table being updated. SEF...
    ''rwIndex = 0
    ''For Each dr In dt.Rows
    '' Try
    '' Select Case dr.RowState
    '' Case DataRowState.Added
    '' astep += 1
    '' ' =======================================================
    '' ' This "Try Catch" section created only if auto numbering
    '' ' is NOT turned on for the table being updated. SEF...
    '' ' It's a crude attempt at creating a unique number.
    '' ' A more serious approach would be to use a GUID.
    '' ' Use only if you decide not to have a sequence and a
    '' ' trigger for the table.
    '' ' =======================================================
    '' Try
    '' 'ds.Tables(tblIndex).Rows(rwIndex).Item(0) = astep
    '' Catch
    '' ' ignore the error corrected integer identity so don't randomize it
    '' End Try
    '' dr.Item("createdDate") = Now
    '' dr.Item("changedDate") = Now
    '' Case DataRowState.Modified
    '' dr.Item("changedDate") = Now
    '' End Select
    '' Catch ex As Exception
    '' conn.Close()
    '' conn.Dispose()
    '' Throw New ArgumentException(" Error: update_datasets " & ex.Message)
    '' End Try
    '' rwIndex += 1
    ''Next
    selectstmt = "SELECT * From " & dt.TableName & " Where " & dt.Columns(0).ColumnName & " = " & 0
    da = New OracleDataAdapter(selectstmt, m_conn)
    Dim bldr As OracleCommandBuilder = New OracleCommandBuilder(da)
    AddHandler da.RowUpdated, New Oracle.DataAccess.Client.OracleRowUpdatedEventHandler(AddressOf da_RowUpdated)
    Dim insCmd As OracleCommand = Nothing
    Try
    insCmd = CType(bldr.GetInsertCommand(), OracleCommand)
    Catch ex As Exception
    Throw New Exception("")
    End Try
    insCmd.CommandText += " returning " + dt.Columns(0).ColumnName + " into :seqno"
    insCmd.Parameters.Add(New OracleParameter("seqno", OracleDbType.Int16, _
    4, ParameterDirection.Output, False, CType(0, System.Byte), CType(0, _
    System.Byte), dt.Columns(0).ColumnName, DataRowVersion.Current, Nothing))
    da.InsertCommand = insCmd
    Try
    ' ===========================
    da.Update(ds, dt.TableName)
    ' ===========================
    Catch ex As Exception
    Throw New ArgumentException(" Error: update_datasets_return " & ex.Message)
    End Try
    Next
    m_conn.Close()
    m_conn.Dispose()
    Return ds
    End Function
    Friend Shared Sub da_RowUpdated(ByVal sender As Object, ByVal e As OracleRowUpdatedEventArgs)
    If e.StatementType = StatementType.Insert Then
    e.Row(0) = Int64.Parse(e.Command.Parameters("seqno").Value.ToString())
    End If
    End Sub
    ' ================================================================================
    ' Notes:
    ' =================== How To -- Sample section for PL/SQL ==================================
    ' myTrigger, myTable, mySequence, and myColumn are values you need to supply.
    ' Note: A trigger needs to be created for each table.
    ' A sequence needs to be created only once and referenced each time
    ' in the trigger(s). Or you could create a new sequence each time you
    ' create a trigger. Sort of a waste of effort.
    ' Explanation:
    ' myTrigger = The name you are giving this trigger.
    ' If a trigger with same name already
    ' exist, it will be overwritten.
    ' myTable = Table you want to add the sequence numbers to.
    ' mySequence = Sequence counter you created. Whatever name you called it.
    ' myColumn = The column to update with the sequence number.
    ' =================================================================================
    ' -- Run in PL/SQL or create at DB. --
    ' create or replace trigger myTrigger
    ' before insert on myTable for each row
    ' begin
    ' select mySequence.nextval into :new.myColumn from dual ;
    ' end;
    ' -- Run in PL/SQL or create at DB. --
    ' create sequence mySequence
    ' MINVALUE 1
    ' START WITH 1
    ' INCREMENT BY 1
    ' NOCACHE; can be set to CACHE but sequence may contain gaps.
    ' Explanation of CACHE from: http://www.techonthenet.com/oracle/sequences.php
    ' With respect to a sequence, the CACHE option specifies how many sequence
    ' values will be stored in memory for faster access. The downside of creating
    ' a sequence with a CACHE is that if a system failure occurs, all cached
    ' sequence values that have not be used, will be "lost". This results in
    ' a "gap" in the assigned sequence values. When the system comes back up,
    ' Oracle will CACHE new numbers from where it left off in the sequence,
    ' ignoring the so called "lost" sequence values.
    ' Note: To recover the lost sequence values, you can always execute an
    ' ALTER SEQUENCE command to reset the counter to the correct value.
    ' NOCACHE means that none of the sequence values are stored in memory.
    ' This option may sacrifice some performance, however, you should not encounter
    ' a gap in the assigned sequence values.
    End Class
    C#:
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class OracleUpdater2
    private static OracleConnection m_conn;
    private static OracleDataAdapter da = new OracleDataAdapter();
    private static OracleConnection conn = new OracleConnection();
    public static DataTable load_it(string constr, string strqry, string tblName)
    // =====================================================================
    // constr = User Id=myUser;Password=myPass";Data Source=myDataSource
    // strqry = Select * from something?
    // tblName = The table name to fill.
    // =====================================================================
    conn = new OracleConnection(constr);
    conn.Open();
    da = new OracleDataAdapter(strqry, conn);
    OracleCommandBuilder bldr = new OracleCommandBuilder(da);
    DataTable dt = new DataTable(tblName);
    da.Fill(dt);
    conn.Dispose();
    return dt;
    public static DataSet update_datasets_return(string constr, DataSet ds)
    //'ByRef ds As DataSet)
    string selectstmt = null;
    m_conn = new OracleConnection(constr);
    try
    m_conn.Open();
    catch (Exception ex)
    throw new ArgumentException(" Error: connection lost." + ex.Message);
    foreach (DataTable dt in ds.Tables)
    selectstmt = "SELECT * From " + dt.TableName + " Where " +
    dt.Columns[0].ColumnName + " = " + 0;
    da = new OracleDataAdapter(selectstmt, m_conn);
    OracleCommandBuilder bldr = new OracleCommandBuilder(da);
    da.RowUpdated += new
    Oracle.DataAccess.Client.OracleRowUpdatedEventHandler(da_RowUpdated);
    OracleCommand insCmd = null;
    try
    insCmd = (OracleCommand)(bldr.GetInsertCommand());
    catch (Exception ex)
    throw new Exception("" + ex.Message);
    insCmd.CommandText += " returning " + dt.Columns[0].ColumnName + " into
    :seqno";
    insCmd.Parameters.Add(new OracleParameter("seqno", OracleDbType.Int16, 4,
    ParameterDirection.Output, false, System.Convert.ToByte(0),
    System.Convert.ToByte(0), dt.Columns[0].ColumnName, DataRowVersion.Current,
    null));
    da.InsertCommand = insCmd;
    try
    // ===========================
    da.Update(ds, dt.TableName);
    // ===========================
    catch (Exception ex)
    throw new ArgumentException(" Error: update_datasets_return " +
    ex.Message);
    m_conn.Close();
    m_conn.Dispose();
    return ds;
    If you need a working program of how this works, let me know.

    Oh my god, it is too long! You definitely check out types, casting and especially ODP.Net (it does everything for you)... etc. They can help you to simplify your code. I do not have enough time to copy paste it to Studio and understand and solve your issue, so I got title of your message as your main question.
    In Oracle, you can create an autonumber field by using sequences object. This is really useful when you need to create a unique number to act as a primary key.
    Basically you can create a sequence simply typing;
    CREATE SEQUENCE MY_SEQUENCE;
    now you have a sequence called "MY_SEQUENCE"... Then, I advice you select a number from sequence;
    select MY_SEQUENCE.nextval from dual;
    I said I advice actually kinda must, although it called sequence, I cannot be sequential. Do not even try to predict the value. You can be sure that it is unique number so you can use it.
    Then insert you record and use that number part of your primary key. I think that's it. Have fun.

  • Creating entity beans with auto numbered primary key

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

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

  • How to have an auto increment primary key in HDBDD

    Hello,
    Using a HDBDD file I am creating a table in which I need a primary key(recordId) which is auto generated by the DB.
    What would be the way to do this?
    My hdbdd file:
    namespace sap.mobile.data;
            @Schema : 'SAP_TEST'
    context Sample {
    @Catalog.tableType : #COLUMN
      entity Details {
      text : LargeString;
      level : String(10);
      timestamp : UTCTimestamp;
      recordId : ?

    Such syntax for calculated columns isn't supported yet by CDS/HDBDD. The work around people would use today is to use a Sequence in any logic that does an insert into this table.

  • CMP with auto-increment primary key.Please help

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

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

  • Retrieving auto inc primary key from entity bean (MySQL DB)

    Hello,
    I searched the forum intensively, but did not find an answer for the following problem.
    I've set up an MySQL database "Location" with two fields (ID, Description), ID is my primary key and I've added the AUTO_INCREMENT flag to this field. This works fine, i can add a row in the table with my entity bean "Location" from my session bean :
    Location l = new Location();
    l.setDescription("at home");
    em.persist(l);
    and even when I ask this location back from the DB, there is no problem :
    Location l = em.find(Location.class,1);
    return l.getDescription();
    The rows in the table increment nicely. The problem however is, that you don't allways know the ID. So I would like to do the following from my session bean:
    Location l = new Location();
    l.setDescription("at home");
    em.persist(l);
    int id = l.getId();
    the getID method allways returns a null object. The row is added in the DB, but the auto incremented ID is not returned to the entity bean!
    I know I could solve this by generating the ID's myself, but one of the strengths of autoincrement should be not to have to do this, no?
    If anyone has a clue how to solve this issue, I would very much appreciate it !
    Michiel
    Edited by: Michiel82 on Dec 6, 2007 6:01 AM

    No reactions so far ... this is a work-around for the issue :
    I've created an additional table sequence with two fields: gen_key and gen_value. Then, in my Location entity bean I can add the following:
    @TableGenerator(
    name="locationGen",
    table="sequence",
    pkColumnName="gen_key",
    valueColumnName="gen_value",
    pkColumnValue="location",
    allocationSize=1
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="locationGen")
    @Column(name = "id", nullable=false)
    private Short id;
    This generates the primary key in the bussiness logic, but I would like to get the autogenerated key from my MySQL database (see previous post). Is this perhaps not supported by EJB3.0?
    Michiel

  • Help required to generate primary key sequence

    Hello All,
    I need your help in generating a sequence for primary key in my db table created using java dictionary project in my NWDS 7.3.
    The table column EMPL_ID is a primary and needs to be a sequence. The code in the JPA entity is as below. The underlying database is DB2 on Linux. Kindly help me resolve this issue.
    * The persistent class for the TMP_EMPL_DATA database table.
    @Entity
    @Table(name="TMP_EMPL_DATA")
    public class TmpEmplData implements Serializable {
         private static final long serialVersionUID = 1L;
         @Id
         @SequenceGenerator(name="EMPLID_GENERATOR", sequenceName="EMPID_SEQ", initialValue = 10000, allocationSize = 1)
         @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EMPLID_GENERATOR")
         @Column(name="EMPL_ID")
         private String _emplId_;
    My bean class contains a public method as follows.
    public TmpEmplData createEmployee(String employeeName, int age, String location)
             TmpEmplData emplData = new TmpEmplData();
             emplData.set_emplName_(employeeName);
             emplData.setAge(age);
             emplData.setLocation(location);
             entityManager.persist(emplData);
             entityManager.find(TmpEmplData.class, emplData.get_emplId_());
             return emplData;
    During execution, i am getting an error as below.
    Caused by: javax.persistence.PersistenceException: The generated SQL statement is not valid for the underlying database platform (platform no. 99). For more details see attached exception. SQL statement is SELECT NEXT VALUE FOR "EMPID_SEQ" FROM ( VALUES (1) )
    at com.sap.engine.services.orpersistence.sqlmapper.mapping.JPASQLMapperImpl.createSequenceIDGeneratorSelectText(JPASQLMapperImpl.java:1239)
    at com.sap.engine.services.orpersistence.entitymanager.CachedJPASQLMapper.createSequenceIDGeneratorSelectText(CachedJPASQLMapper.java:259)
    at com.sap.engine.services.orpersistence.generator.GeneratorFactory.<init>(GeneratorFactory.java:156)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl$MetaDataImpl.<init>(EntityManagerFactoryImpl.java:323)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:137)
    at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.<init>(JtaEntityManagerFactoryImpl.java:39)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createJtaEntityManagerFactory(PersistenceProviderImpl.java:251)
    at com.sap.engine.services.orpersistence.provider.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:236)
    at com.sap.engine.services.orpersistence.container.EMFInstanceCreator.getEntityManagerFactory(EMFInstanceCreator.java:134)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getEMF(ORPersistenceObjectFactory.java:300)
    at com.sap.engine.services.orpersistence.container.ORPersistenceObjectFactory.getObjectInstance(ORPersistenceObjectFactory.java:73)
    at com.sap.engine.lib.injection.ReferenceObjectFactory.getObject(ReferenceObjectFactory.java:96)
    at com.sap.engine.lib.injection.FieldInjector.inject(FieldInjector.java:113)
    ... 122 more
    Caused by: com.sap.engine.services.orpersistence.sqlmapper.generate.SQLMappingException: SQL statement is not valid for underlying database platform.
    at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMappingResult.getStatementString(CommonSQLMappingResult.java:237)
    at com.sap.engine.services.orpersistence.sqlmapper.mapping.JPASQLMapperImpl.createSequenceIDGeneratorSelectText(JPASQLMapperImpl.java:1237)
    ... 134 more
    Caused by: com.sap.sql.tree.StringRepresentationFailureException: Cannot represent next value expression as string.
    at com.sap.sql.tree.impl.OpenSqlTextExpert.nextValueExpressionToText(OpenSqlTextExpert.java:185)
    at com.sap.sql.tree.impl.NextValueExpressionBuilderImpl$NextValueExpressionImpl.toSqlTxt(NextValueExpressionBuilderImpl.java:140)
    at com.sap.sql.tree.impl.AbstractSqlTextExpert.selectSublistToText(AbstractSqlTextExpert.java:130)
    at com.sap.sql.tree.impl.SelectSublistImpl.toSqlTxt(SelectSublistImpl.java:150)
    at com.sap.sql.tree.impl.QuerySpecificationImpl.toSqlTxt(QuerySpecificationImpl.java:361)
    at com.sap.sql.tree.impl.SelectStatementImpl.toSqlTxt(SelectStatementImpl.java:139)
    at com.sap.sql.tree.impl.SQLStatementImpl.toSqlString(SQLStatementImpl.java:75)
    at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMappingResult.getStatementString(CommonSQLMappingResult.java:233)
    ... 135 more

    Hi,
    does the sequence exist? SAP JPA does not support creation of sequences, you have to create it manually.
    Maybe SAP JPA also does not support DB2 sequences with "Open SQL" correctly.
    - Tryp to set your data source to "native" or "vendor".
    - Try to turn on oracle compatibility:
    db2set DB2_COMPATIBILITY_VECTOR=ORA
    Regards
    Rolf

  • CMP with Auto-increment Primary Key problem

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

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

  • Auto Increment Primary Keys

    I am trying to migrate from SQL Server. I want to setup tables which generate sequencial Primary keys on adding records to the table. I have a VB application which is using ADO with an ODBC connection. How does one use the Oracle Enterprise Console Manager to set a Primary Key to increment on the adding of new records automatically. In SQL Server one just needs to set an Identity, Identity Seed and Identitiy Increment. In Access there is a datatype called AutoNumber. Help would be greatly appreciated. I am using 9i with a standalone Enterprise Console Manager. Thanks in Advance.

    You first have to create a sequence and then the trigger below:
    Instead of data in single quotes(') you must specify the appropriate for your db names
    CREATE OR REPLACE TRIGGER 'Schema'.'trigger_name' BEFORE
    INSERT ON 'table_name'
    FOR EACH ROW
    BEGIN
    SELECT 'sequence_name'.nextval into :new.'column_name' from dual;
    END
    ;

Maybe you are looking for

  • ICal Calendar Colors Changing by Themselves

    I have two devices that sync with my iCloud account, a Macbook Pro and an iPhone 5. I primarily use iCloud to sync my calendar, notes, and reminders. By some reason when I got home from work last night, the color of every calendar in iCal (on the Mac

  • Live streaming from mp4 file

    Hello everybody, I know that's a noob question (as I am) but i can't make it run. I have an mp4 file and the folders structure is.... Application/test/sources/_definst_ in _definst_ source.mp4 in test folder main.asc file main.asc file contains var m

  • JNLP : Launch File Error

    Hi All, am unable find the file.. (Could not find main-class) am using J2se 1.4 and Jboss 4.0 i have created all my class file and make it as JMSconsumer.jar then i create JMSClient.war ==>MANIFEST.MF web.xml , all .Jar files and JmsClient.JNLP while

  • Nokia online shop UK

    Hi I've asked customer services this question twice now and they haven't answered it - does anyone know what courier company Nokia use to deliver phones bought on their UK website? I always have problems getting these courier companies to re-deliver

  • Hello can i create accounts in another countries with foreign credit cards?

    Hi im making a developer apple ID so i can create and sell apps in the app store (obviously) but i'd like to know if i can make a developer account for say the US app store with a credit card not issued in that country is that possible?