EjbCreate returns primary key - auto increment

ejbCreate of a BMP entity bean must return the primary key.
If i have an auto-incrementer (in MySQL) and i insert the new data in this method, how can i then find the primary key to return?
Surely i cannot just use a select statement in another method as the other data in the table may not be unique and may not return the correct primary key.
Help Please
Thanks
Dave

Hi,
PreparedStatement ps = con.prepareStatement("INSERT INTO food_data (description)" + " VALUES (?)");
//Get generated primary key
ResultSet res = ps.getGeneratedKeys();
while (res.next())
{     key = res.getInt(1);
This code requires JDK 1.4.2.
Any other soln for previous versions of JDK (1.4.1 or 1.3.1)
Seetesh

Similar Messages

  • DB Adapter - PostgreSQL - Primary key - auto increment handling

    Hi,
    I have to connect to a PostgreSQL DB. I have a table in which has a primary key called seq_id. This seq_id is being incremented using a sequence.
    I have to configure the DB adapter for this table. The problem is that while creating the adapter it does not allow me to deselect the primary key (seq_id). Because of this I have to supply a value for the seq_id while inseting the data using the adapter. But this defeats the purpose of sequence (auto increment).
    Is there a way to get around this and to avoid specifying the value for seq_id while using the DB Adapter and let it get inserted using the sequence of the DB?
    Thanks,
    Sanjay

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

  • Insert into table returning primary key (auto number) in resultset

    Hi,
    I'm connecting to Oracle 10g via JDBC (ojdbc14.jar).
    My SQL statement is as follows:
    INSERT into Student (studentName, phone, email, address) values ('Jason', '12345678', 'test', 'test');
    SELECT Student_studentId_SEQ.NEXTVAL FROM DUAL;
    Fyi -The Student table has a trigger to support the generation of a primary key (integer) based on a sequence when a new record is inserted.
    What the above will do (from the Java app point of view) is to create a Student record and automatically select the student ID so that the student ID can be accessed via the resultset in Java.
    I'm getting error "ORA-00911: invalid character". Can you please help?
    Regards,
    Jason
    Edited by: user10394130 on Oct 13, 2008 2:40 AM

    Yes, I'm referring to the studentId, which is generated via the Student table trigger on insert of a new record.
    I've now verified that the following SQL works and it is "printing" the correct studentId.
    DECLARE seqNbr_studentId NUMBER(12) := 0;
    BEGIN
    INSERT into Student (studentName, phone, email, address) values ('Jason', '12345678', 'test', 'test')
    RETURNING studentId INTO seqNbr_studentId;
    dbms_output.put_line(seqNbr_studentId);
    END;
    --> This prints the correct value of seqNbr_studentId that has been generated by the trigger. This is good.
    However, I would like the studentId to be in a resultset (so that I can access this via Java Resultset.getInt(1) ), for example:
    DECLARE seqNbr_studentId NUMBER(12) := 0;
    BEGIN
    INSERT into Student (studentName, phone, email, address) values ('Jason', '12345678', 'test', 'test')
    RETURNING studentId INTO seqNbr_studentId;
    SELECT seqNbr_studentId FROM DUMMYTABLE;
    END;
    Is this possible?
    What I'm trying to do is to achieve the effect in SQL Server where I can simply do an SQL command "SELECT @@IDENTITY" where it returns the auto number from the newly inserted record.
    Regards,
    Jason
    Edited by: user10394130 on Oct 13, 2008 2:08 AM
    Edited by: user10394130 on Oct 13, 2008 2:56 AM

  • EjbCreate() method return primary key genereted by database

    Hello Everyone,
    I have entity CMP EJB that maps MySQL database table, which is set to asign Primary key (integer) to new entries automatically by using AUTO_INCREMENT. The problem is ejbCreate(..) method, which returns primary key. My question is: how to make it return primary key generated by database?
    Thanks

    Hi,
    I'm also facing the same problem also. The problem is: how do I code the ejbCreate method?
    If I don't initialize the primary key field, I get a complaint that the primary key field needs to be initialized in ejbCreate.
    But if I try to initialize it to an arbitrary value, the database won't allow me to do the insert, because the primary key is auto-generated.

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

  • Auto incremented field mobile device

    hello,
    my colleague requires to make a mechanism in the mobile device (oracle lite client) where the primary field of a table is automatically incremented.
    according to the documentation in order to make that happen in a consistent manner so that all clients can sync correctly without ambiguities , we created a sequence
    through the MDW and attached it to the publication. then with the sync , this sequence has been downloaded to all clients and each one has a specified window.
    now we suppose that we must create the trigger that uses this sequence in order to provide the correct primary key field.
    lets say that the sequence is names SYSTEM.AUTOINCSEQUENCEA
    the table is named SYSTEM.TABLEA
    and the primary key that we want to auto incr is named ID.
    the trigger we suppose that should look like:
    CREATE TRIGGER SYSTEM.TRIGGERTABLEA
    BEFORE INSERT
    ON SYSTEM.TABLEA REFERENCING NEW AS New OLD AS Old
    FOR EACH ROW
    BEGIN
    select AUTOINCSEQUENCEA.nextval into :new.ID from dual;
    END ;
    1)But if i execute this from the msql on the client device (mobile windows device) it returns a "syntax error". how can i create the trigger that i need which will use my sequence in order
    to appoint the new values on the primary key (auto incremented field??) .
    2)if i cant do it through a normal sql statement then how can i do it?
    thank you

    You need Java Store Procedure as the trigger. PL/SQL is not support on the Oracle Lite client.
    Let me know if you need an example on how to do this.

  • How to re-order automatically the number of primary key column in MySql that has been set as auto_increment if one of the row deleted?

    Hello,
    Can anyone show me the way how to re-oder automatically the number of primary key that has been set as auto_increment in mysql database when the row deleted?
    example:
    No (primary key=auto increment)|
    Name |
    AGE |
    1
        | JO
    | 21
    |
    2
        | Kyle
    | 25
    |
    3
        | Macy
    | 30
    |
    When delete 1 row:
    No (primary key=auto increment)|
    Name |
    AGE |
    1
        | JO
    | 21
    |
    2
        | Macy
    | 30
    |

    Hello,
    This is not a VB.NET question, best to ask this question in
    MySQL forum.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

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

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

  • 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

  • How can I use a mySQL database schema with numeric auto increment primary key instead of GUID?

    Hello!
    I'm using the TestStand "MySQL Insert (NI)" database schema with GUID as primary key. So everything works fine.
    But I prever using numeric values as primary key, because the database is in conjunction with another database which uses numeric values as primary key.
    Is this possible?
    Has anyone an idea how I can modify the "Generic Recordset (NI)" for use with MySQL?
    Thanks!
    Configuration:
    Microsoft Windows XP
    TestStand 3.1
    MySQL 4.1.12a
    MySQL ODBC 3.51 Driver
    Brosig

    Adam -
    The TestStand Database Logging feature does not allow you to run a separate SQL command after executing the command for a statement(table), so I do not think that you can use an auto incrementing column for the tables. There is just no way to get it back in a generic way. One option that I tried is something similar to the Oracle schema where you call a store procedure to return a sequence ID for each record that you want to add.
    So you would have to create the following sequence table in MySQL:
    CREATE TABLE sequence (id INT NOT NULL);
    INSERT INTO sequence VALUES (0);
    Then create a stored procedure as shown below that will increment the sequence value and return it in a recordset:
    CREATE PROCEDURE `getseqid`()
    BEGIN
            UPDATE sequence SET id=LAST_INSERT_ID(id+1);
            SELECT LAST_INSERT_ID();
    END
    Then update the MySQL tables to use INT primary and foreign key values, so the TestStand MySQL SQL file to create all tables would have text like this:
    CREATE TABLE UUT_RESULT
     ID    INT  PRIMARY KEY,
    ~
    CREATE TABLE STEP_RESULT
     ID    INT  PRIMARY KEY,
     UUT_RESULT   INT  NOT NULL,
    ~
    Then update the schema primary and foreign key columns in the TestStand Database Options dialog box to be INT to match the table. For the primary key columns, you will have to set the Primary Key Type to "Get Value from Recordset" and set the Primary Key Command Text to "call getseqid()". This will call the stored procedure to determine the next value to use as the ID value.
    Hope this helps...
    Scott Richardson
    National Instruments

  • Javax.ejb.EJBException: Null primary key returned by ejbCreate method

    Hi all,
    I'm using SunOne 7.1 and I got this error when I call the create on the CMP bean.
    javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: javax.ejb.EJBException: Null primary key returned by ejbCreate method
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: javax.ejb.EJBException: Null primary key returned by ejbCreate method
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.sun.ejb.containers.EntityContainer.postCreate(EntityContainer.java:801)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at uk.co.upco.workflow.applicationAdmin.ejb.ApplicationAdminBean_854379388_ConcreteImpl_LocalHomeImpl.createNewApplication(ApplicationAdminBean_854379388_ConcreteImpl_LocalHomeImpl.java:64)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at uk.co.upco.workflow.sessionFacedeApplicationAdmin.SFApplicationAdminBean.insertNewApplicationName(SFApplicationAdminBean.java:64)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at uk.co.upco.workflow.sessionFacedeApplicationAdmin.SFApplicationAdminBean_EJBObjectImpl.insertNewApplicationName(SFApplicationAdminBean_EJBObjectImpl.java:31)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at uk.co.upco.workflow.sessionFacedeApplicationAdmin._SFApplicationAdminBean_EJBObjectImpl_Tie._invoke(Unknown Source)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:569)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:211)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:113)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:275)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:83)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.iplanet.ias.corba.ee.internal.iiop.ServicableWrapper.service(ServicableWrapper.java:25)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at com.iplanet.ias.util.threadpool.FastThreadPool$ThreadPoolThread.run(FastThreadPool.java:283)
    [14/Aug/2004:01:15:34] WARNING ( 4044): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    cmp:
    public java.lang.Integer ejbCreateNewApplication(java.lang.String application) throws javax.ejb.CreateException {
    setApplication(application);
    return null;
    The key is auto_increment and is an integer.
    I'm usin MySQL and it is already set up as ANSI. (running as mysqld --ansi)
    Any Idea?
    Thanks in advance

    What happend when two concourrent user try to get the same key on the table? If for example I have 30 users at same time do I have lock table?
    Any way here the finest log using sunone 8. The error is the same, so I think I missing something:
    [#|2004-08-14T12:11:19.296+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.util|_ThreadID=11;|IM: preInvokeorg.apache.catalina.servlets.DefaultServlet@1acecf3|#]
    [#|2004-08-14T12:11:19.296+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.util|_ThreadID=11;|IM: postInvokeorg.apache.catalina.servlets.DefaultServlet@1acecf3|#]
    [#|2004-08-14T12:11:26.166+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: returning cached ProtectionDomain - CodeSource: ((file:/Test <no certificates>)) PrincipalSet: null|#]
    [#|2004-08-14T12:11:26.166+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: Changing Policy Context ID: oldV = null newV = Test|#]
    [#|2004-08-14T12:11:26.166+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: Access Control Decision Result: true EJBMethodPermission (Name) = SFApplicationAdmin (Action) = create,Home, (Codesource) = (file:/Test <no certificates>)|#]
    [#|2004-08-14T12:11:26.186+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: returning cached ProtectionDomain - CodeSource: ((file:/Test <no certificates>)) PrincipalSet: null|#]
    [#|2004-08-14T12:11:26.186+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: Access Control Decision Result: true EJBMethodPermission (Name) = SFApplicationAdmin (Action) = insertNewApplicationName,Remote,java.util.Hashtable (Codesource) = (file:/Test <no certificates>)|#]
    [#|2004-08-14T12:11:26.186+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.util|_ThreadID=22;|IM: preInvokeuk.co.myDomain.workflow.sessionFacedeApplicationAdmin.SFApplicationAdminBean@1fa487f|#]
    [#|2004-08-14T12:11:26.186+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: doAsPrivileged contextId(Test)|#]
    [#|2004-08-14T12:11:26.186+0100|INFO|sun-appserver-pe8.0|javax.enterprise.system.stream.out|_ThreadID=22;|
    new|#]
    [#|2004-08-14T12:11:26.186+0100|INFO|sun-appserver-pe8.0|javax.enterprise.system.stream.out|_ThreadID=22;|
    mgmt: com.sun.enterprise.naming.TransientContext:com.sun.enterprise.naming.TransientContext@ad00b2|#]
    [#|2004-08-14T12:11:26.186+0100|INFO|sun-appserver-pe8.0|javax.enterprise.system.stream.out|_ThreadID=22;|
    new|#]
    [#|2004-08-14T12:11:26.186+0100|INFO|sun-appserver-pe8.0|javax.enterprise.system.stream.out|_ThreadID=22;|
    SFApplicationAdmin: javax.naming.Reference:Reference Class Name: reference
    Type: url
    Content: ejb/SFApplicationAdmin
    |#]
    [#|2004-08-14T12:11:26.186+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: returning cached ProtectionDomain - CodeSource: ((file:/Test <no certificates>)) PrincipalSet: null|#]
    [#|2004-08-14T12:11:26.186+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.core.security|_ThreadID=22;|JACC: Access Control Decision Result: true EJBMethodPermission (Name) = ApplicationAdmin (Action) = createNewApplication,LocalHome,java.lang.String (Codesource) = (file:/Test <no certificates>)|#]
    [#|2004-08-14T12:11:26.196+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.container.ejb|_ThreadID=22;|[Pool-ApplicationAdmin]: Added PoolResizeTimerTask...|#]
    [#|2004-08-14T12:11:26.196+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.util|_ThreadID=22;|IM: preInvokeuk.co.myDomain.workflow.applicationAdmin.ejb.ApplicationAdminBean_1421299025_ConcreteImpl@7ae165|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|:Thread[Worker: 16,5,org.apache.commons.launcher.ChildMain] -->SQLPersistenceManagerFactory.getPersistenceManager().|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|Thread[Worker: 16,5,org.apache.commons.launcher.ChildMain] <->SQLPersistenceManagerFactory.getPersistenceManager() FOUND javax.transaction.Transaction: com.sun.ejb.containers.PMTransactionImpl@5.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|<--SQLPersistenceManagerFactory.getFromPool().|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|PersistenceManagerImpl cache properties: _txCacheInitialCapacity=20, _flushedCacheInitialCapacity=20, _flushedCacheLoadFactor=0.75, _weakCacheInitialCapacity=20, _weakCacheLoadFactor=0.75.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.utility|_ThreadID=22;|NullSemaphore constructor() for PersistenceManagerImpl.cacheLock.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.utility|_ThreadID=22;|NullSemaphore constructor() for PersistenceManagerImpl.fieldUpdateLock.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|<--SQLPersistenceManagerFactory.getFromPool() PM: com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerImpl@8d18c for JTA com.sun.ejb.containers.PMTransactionImpl@5.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|<->SQLPersistenceManagerFactory.getPersistenceManager() JDO Transaction:   Transaction:
    status = STATUS_NO_TRANSACTION
    Transaction Object = Transaction@16077795
    threads = 0
    .|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.transaction|_ThreadID=22;|Thread[Worker: 16,5,org.apache.commons.launcher.ChildMain] Tran[   Transaction:
    status = STATUS_NO_TRANSACTION
    Transaction Object = Transaction@16077795
    threads = 0
    ].begin:status = STATUS_NO_TRANSACTION ,txType: UNKNOWN for com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerImpl@8d18c.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.transaction|_ThreadID=22;|Thread[Worker: 16,5,org.apache.commons.launcher.ChildMain] Tran[   Transaction:
    status = STATUS_NO_TRANSACTION
    Transaction Object = Transaction@16077795
    threads = 0
    ].setStatus: STATUS_NO_TRANSACTION => STATUS_ACTIVE for com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerImpl@8d18c.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|Thread[Worker: 16,5,org.apache.commons.launcher.ChildMain] <->SQLPersistenceManagerFactory.getPersistenceManager() : com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerImpl@8d18c for JTA: com.sun.ejb.containers.PMTransactionImpl@5.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|---PersistenceManagerImpl.getCurrentWrapper() > current: null.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|---PersistenceManagerImpl.pushCurrentWrapper() > current: null  new: com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerWrapper@567117.|#]
    [#|2004-08-14T12:11:26.196+0100|FINEST|sun-appserver-pe8.0|javax.enterprise.resource.jdo.persistencemanager|_ThreadID=22;|---PersistenceManagerImpl.popCurrentWrapper() > current: com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerWrapper@567117  prev: null.|#]
    [#|2004-08-14T12:11:26.196+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.util|_ThreadID=22;|IM: postInvokeuk.co.myDomain.workflow.applicationAdmin.ejb.ApplicationAdminBean_1421299025_ConcreteImpl@7ae165|#]
    [#|2004-08-14T12:11:26.196+0100|FINE|sun-appserver-pe8.0|javax.enterprise.system.container.ejb|_ThreadID=22;|Exception in forceDestroyBean()
    java.lang.IllegalStateException: Primary key not available
         at com.sun.ejb.containers.EntityContextImpl.getPrimaryKey(EntityContextImpl.java:114)
         at com.sun.ejb.containers.EntityContainer.forceDestroyBean(EntityContainer.java:1232)
         at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:2559)
         at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:2416)
         at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:763)
         at com.sun.ejb.containers.EJBLocalHomeInvocationHandler.invoke(EJBLocalHomeInvocationHandler.java:197)
         at $Proxy10.createNewApplication(Unknown Source)
         at uk.co.myDomain.workflow.sessionFacedeApplicationAdmin.SFApplicationAdminBean.insertNewApplicationName(SFApplicationAdminBean.java:64)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:146)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:930)
         at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:151)
         at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:128)
         at $Proxy7.insertNewApplicationName(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:117)
         at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:651)
         at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:190)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1653)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1513)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:895)
         at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:172)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:668)
         at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:375)
         at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.read(SocketOrChannelConnectionImpl.java:284)
         at com.sun.corba.ee.impl.transport.ReaderThreadImpl.doWork(ReaderThreadImpl.java:73)
         at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:382)
    |#]
    [#|2004-08-14T12:11:26.196+0100|INFO|sun-appserver-pe8.0|javax.enterprise.system.container.ejb|_ThreadID=22;|EJB5018: An exception was thrown during an ejb invocation on [ApplicationAdmin]|#]
    [#|2004-08-14T12:11:26.196+0100|INFO|sun-appserver-pe8.0|javax.enterprise.system.container.ejb|_ThreadID=22;|
    javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: java.lang.IllegalArgumentException: JDO73013: Primary Key field applicationId for bean 'ApplicationAdmin' cannot be null.
    java.lang.IllegalArgumentException: JDO73013: Primary Key field applicationId for bean 'ApplicationAdmin' cannot be null.
         at com.sun.jdo.spi.persistence.support.ejb.cmp.JDOEJB11HelperImpl.assertPrimaryKeyFieldNotNull(JDOEJB11HelperImpl.java:446)
         at uk.co.myDomain.workflow.applicationAdmin.ejb.ApplicationAdminBean_1421299025_ConcreteImpl.setApplicationId(ApplicationAdminBean_1421299025_ConcreteImpl.java:102)
         at uk.co.myDomain.workflow.applicationAdmin.ejb.ApplicationAdminBean.ejbCreateNewApplication(ApplicationAdminBean.java:93)
         at uk.co.myDomain.workflow.applicationAdmin.ejb.ApplicationAdminBean_1421299025_ConcreteImpl.ejbCreateNewApplication(ApplicationAdminBean_1421299025_ConcreteImpl.java:334)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:140)
         at com.sun.ejb.containers.EJBLocalHomeInvocationHandler.invoke(EJBLocalHomeInvocationHandler.java:168)
         at $Proxy10.createNewApplication(Unknown Source)
         at uk.co.myDomain.workflow.sessionFacedeApplicationAdmin.SFApplicationAdminBean.insertNewApplicationName(SFApplicationAdminBean.java:64)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:146)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:930)
         at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:151)
         at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:128)
         at $Proxy7.insertNewApplicationName(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:117)
         at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:651)
         at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:190)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1653)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1513)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:895)
         at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:172)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:668)
         at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:375)
         at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.read(SocketOrChannelConnectionImpl.java:284)
         at com.sun.corba.ee.impl.transport.ReaderThreadImpl.doWork(ReaderThreadImpl.java:73)
         at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:382)
    javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: java.lang.IllegalArgumentException: JDO73013: Primary Key field applicationId for bean 'ApplicationAdmin' cannot be null.
         at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:2564)
         at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:2416)
         at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:763)
         at com.sun.ejb.containers.EJBLocalHomeInvocationHandler.invoke(EJBLocalHomeInvocationHandler.java:197)
         at $Proxy10.createNewApplication(Unknown Source)
         at uk.co.myDomain.workflow.sessionFacedeApplicationAdmin.SFApplicationAdminBean.insertNewApplicationName(SFApplicationAdminBean.java:64)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:146)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:930)
         at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:151)
         at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:128)
         at $Proxy7.insertNewApplicationName(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:117)
         at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:651)
         at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:190)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1653)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1513)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:895)
         at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:172)
         at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:668)
         at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:375)
         at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.read(SocketOrChannelConnectionImpl.java:284)
         at com.sun.corba.ee.impl.transport.ReaderThreadImpl.doWork(ReaderThreadImpl.java:73)
         at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:382)
    |#]
    Any Idea?
    Thanks in advance for any help

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

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

  • Primary key column auto increment

    Hello,
    In my Azure SQL Database I noticed that weird thing is happening. I have table with primary key column with auto increment, and all works fine, on new insert that value automatically increment, but every now and then, that value, for no reason, increments
    for 1000.
    For instance i have in DB values in this order: 1, 2, 3, 4, 1001, 1002, 1003, 2004,  2005, 3001, 3002...
    Why is this happening? 

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

Maybe you are looking for

  • Won't Open Any Documents

    Hi all, I'm pretty new to Illustrator and I'm currently using Illustrator CS6 v16.0.0 x32 on Windows 7. I'm having an issue where it's not letting me open any documents or basically use it... hence the long description: When I load the program, every

  • How can I scan to more than one specific folder?

    For example, I want to scan in a document from the printer but want it to go into folder A. Next I want to scan another document but I want it to go into folder B. I know how to create a permanent destination for my scans, what I want to know is, is

  • Large image help needed please

    Hey all, I hope you can help - at this point I am nearing tears of frustration.. I have been working with CS4 for a month or so and just got a colour scanner. Installation of the scanner etc. went fine and I can now scan my artwork in to the pc. I kn

  • Tomcat WebApp Deployment question

    I am very new to tomcat and trying to get my very first web application up and running. This is the web app from the book Head First Servlet and JSP named Beer-v1 Tomcat version: 5.0.28 Platform: Windos 2000 Problem: I have following structure c:\tom

  • Rendering an image to a file

    I would like to be able to render an image (save as jpeg) that is normaly displayed to a swing canvas using the Graphics2D library to a file. The problem is that I want to do this when the DISPLAY env var is not set. If this is impossible, is there s