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?

Similar Messages

  • 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

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

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

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

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

  • 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

  • Auto increment of key in TopLink (by Anizio)

    Hi friends!
    Sameone know how I do auto increment of key when I insert an object on the data base with topLink?
    I have used to Jdeveloper 1013
    Thank

    Hi Doug
    I tryed but happened a error.
    I do this: in my descriptor, I enable the options "Use sequencing", then, this is equals:
    Name: SEQ_ID_TITULAR
    Table: DEVPORTAL.CAD_TITULAR
    Fiels: CAD_TITULAR.TIT_ID
    In the name I put the sequence name created in the database, but an error called "invalid number" happen.
    Can you help me ?

  • Entity bean - Unknow primary key problem

    Hi,
    We are using entity bean with unknown primary key option to generate the primary key automatically. It works for all the tables except one table. What we observe is, auto generated primary key is less than the max value in the table and is clashing with one existing record. Any thoughts on what could be wrong?
    Your help is highly appreciated.
    Regards,
    Chandra
    Edited by: Chandrashekhar Singh on Mar 3, 2008 6:39 PM

    Hi,
    I think Vladimir's answer can help you.
    [Entity bean - getting Duplicate Key Exception on ejbCreate;
    Regards
    Pavel

  • Replication for Data on DEV and QA - bad idea - primary key problem now

    I goofed.  I tried to use replication to keep the data on my dev machine up to date with the live server.  Now when I try to work on the database, adding new stuff, it fails.  It says there is a primary key problem every time I try to add
    a new item to a table with my program.  I should have realized this would happen!  Now, even though I've removed the replication, I'm having the problem.  Can anyone help me get my database functional again :/  Or should I resort to a database
    restore.  Thanks!

    So you have an IDENTITY column in your table? Run a
    DBCC CHECKIDENT (Transact-SQL) command with option RESEED to fix the current identity value to see if it works then.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Oracle 10g express edition primary key problem

    Hi , i have a database with varchar as primary key eg.SEG. however after i insert row and set priamry key as SEG , the primary key will be displayed as number eg.1 and not SEG. Why is it so?

    835401 wrote:
    Table Data Indexes Model Constraints Grants Statistics UI Defaults Triggers Dependencies SQL
    CREATE TABLE "TEST_DEPARTMENT"
    (     "DEPT_CODE" VARCHAR2(10) NOT NULL ENABLE,
         "DEPT_NAME" VARCHAR2(50),
         CONSTRAINT "TEST_DEPARTMENT_PK" PRIMARY KEY ("DEPT_CODE") ENABLE
    CREATE OR REPLACE TRIGGER "BI_TEST_DEPARTMENT"
    before insert on "TEST_DEPARTMENT"
    for each row
    begin
    select "TEST_DEPARTMENT_SEQ".nextval into :NEW.DEPT_CODE from dual;
    end;
    ALTER TRIGGER "BI_TEST_DEPARTMENT" ENABLE
    This is my SQLSo why is DEPT_CODE defined as VARCHAR2(10) when you are going to populate it (via the trigger) with a NUMBER?

  • Error While Deploying A CMP Entity Bean With A Composite Primary Key

    Hello all,
    I have a problem deploying CMP Entity beans with composite primary keys. I have a CMP Entity Bean, which contains a composite primary key composed of two local stubs. If you know more about this please respond to my post on the EJB forum (subject: CMP Bean Local Stub as a Field of a Primary Key Class).
    In the mean time, can you please tell me what following error message means and how to resolve it? From what I understand it might be a problem with Sun ONE AS 7, but I would like to make sure it's not me doing something wrong.
    [05/Jan/2005:12:49:03] WARNING ( 1896):      Validation error in bean CustomerSubscription: The type of non-static field customer of the key class
    test.subscription.CustomerSubscriptionCMP_1530383317_JDOState$Oid must be primitive or must implement java.io.Serializable.
         Update the type of the key class field.
         Warning: All primary key columns in primary table CustomerSubscription of the bean corresponding to the generated class test.subscription.CustomerSubscriptionCMP_1530383317_JDOState must be mapped to key fields.
         Map the following primary key columns to key fields: CustomerSubscription.CustomerEmail,CustomerSubscription.SubscriptionType. If you already have fields mapped to these columns, verify that they are key fields.Is it enough that a primary key class be serializable or all fields have to implement Serializable or be a primitive?
    Please let me know if you need more information to answer my question.
    Thanks.
    Nikola

    Hi Nikola,
    There are several problems with your CMP bean.
    1. Fields of a Primary Key Class must be a subset of CMP fields, so yes, they must be either a primitive or a Serializable type.
    2. Sun Application Server does not support Primary Key fields of an arbitrary Serializable type (i.e. those that will be stored
    as BLOB in the database), but only primitives, Java wrappers, String, and Date/Time types.
    Do you try to use stubs instead of relationships or for some other reason?
    If it's the former - look at the CMR fields.
    If it's the latter, I suggest to store these fields as regular CMP fields and use some other value as the PK. If you prefer that
    the CMP container generates the PK values, use the Unknown
    PrimaryKey feature.
    Regards,
    -marina

  • Primary key problem using with oc4j

    Hi everyone
    I have deployed my entity bean in the oc4j container without any problem.But when I use the search->primary key in the console,no results display.
    detail:
    Step1I open the oc4j console by typing java -jar orion.jar -console
    the oc4j container is successfully built
    and in the left part of my console I see my entity bean
    step2 I click my entity bean and in the right of the console in the search->primary key I type the a number which exists in my table in the database.
    but no results display.
    the following is my datasource-file anf orion-ejb-jar file
    data-sources.xml
    <?xml version="1.0"?>
    <!DOCTYPE data-sources PUBLIC "-//Evermind//- Data-sources configuration" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
    <data-sources>
         <data-source
              class="com.evermind.sql.DriverManagerDataSource"
              name="jdbc/OracleDSCore"
              location="jdbc/OracleDSCore"
              pooled-location="jdbc/OracleDSPooled"
              xa-location="jdbc/xa/OracleDSXA"
              connection-driver="oracle.jdbc.driver.OracleDriver"
              username="SCOTT"
              password="TIGER"
              url="jdbc:oracle:thin:@localhost:1521:b2b"
         />
    </data-sources>
    orion-ejb-jar.xml
    <?xml version = '1.0' encoding = 'GBK'?>
    <!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
    <orion-ejb-jar>
    <enterprise-beans>
    <entity-deployment name="EMP" data-source="jdbc/OracleDSCore" table="EMP" >
    <primkey-mapping>
    <cmp-field-mapping>
    <fields>
    <cmp-field-mapping name="EMPNO"
    persistence-name="EMPNO" persistence-type="VARCHAR2(4)"/>
    </fields>
    </cmp-field-mapping>
    </primkey-mapping>
    </entity-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="&lt;default-ejb-caller-role>" impliesAll="true"/>
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    Any answer is welcome. Thankou in advance!

    Fernando,
    I see you suffer a lot with ADF...write me at [email protected] and let´s keep in touch.
    Maybe we can do a Brazilian list for JDev/ADF.
    Regards,
    Marcelo Alcantara

  • Problem with foreign and primary keys migration from SQL Server to Oracle

    Hi folks, i'm using SQL Developer to migrate from a SQL Server database to Oracle and i'm stuck with a couple issues:
    The worst of them so far is the fact that i can't migrate any of the PKs and FKs. After successfully capturing the SQL Server DB model and converting it to Oracle, when the tool generates the scripts, all ALTER TABLE queries that add the PKs and FKs have their target columns duplicated.
    for example: when i'm trying to migrate a simple table that contains an Id (PK) and Name columns, the tool generates the following scripts:
    PROMPT Creating Table TestTable...
    CREATE TABLE TestTable (
    Id NUMBER(10,0) NOT NULL,
    Name VARCHAR2 NOT NULL
    PROMPT Creating Primary Key Constraint PK_TestTable on table TestTable ...
    ALTER TABLE TestTable
    ADD CONSTRAINT PK_TestTable PRIMARY KEY
    Id,
    Id
    ENABLE
    As for the FKs, the tool duplicates the columns as well:
    ALTER TABLE SomeTable
    ADD CONSTRAINT FK_SomeTable_SomeTable2 FOREIGN KEY
    SomeTable2Id,
    SomeTable2Id
    REFERENCES SomeTable2
    Id,
    Id
    ENABLE
    Does anyone have a clue on how to solve these issues? I'd be greatly thankful for any answers!

    Hi Fernando,
    I was unable to replicate this issue. My primary / foreign keys where defined using unique columns.
    PROMPT Creating Primary Key Constraint PK_Suppliers on table Suppliers ...
    ALTER TABLE Suppliers
    ADD CONSTRAINT PK_Suppliers PRIMARY KEY
    SupplierID
    ENABLE
    I tried a few things like
    capturing twice and renaming both models the same
    renaming the converted models
    but with no luck.
    I think this issue is occuring either at the capture or convert phase.
    1) Are you performing the capture online or offline?
    2) Can you provide a the entire DDL for one of these tables and its indexes to see if I can replicate?
    3) Did the capture or convert fail or have to be redone at any stage ?
    I all else fails I would attempt a capture and convert again using a brand new repository (create a new schema in Oracle and associate the migration repository with it).
    Regards,
    Dermot
    SQL Developer Team
    Edited by: Dermot ONeill on Oct 22, 2009 12:18 PM

Maybe you are looking for

  • Wrong sy-sysid value

    Hello, An ABAP program which makes use of sy-sysid picks up a wrong value.  The system id is TST, but it picks up production id which is PRD.  Therefore, when user runs transaction that needs to place a text file in the local directory, it is looking

  • ABAP Objects - getting a value of 'h'!!?! - what's going on!!??!?!?

    Howdy, I've got an objects question and its driving me crazy. Basically I have two methods in a class. Method 1 passes values to method 2. Method 2 does some calculations and then passes the values to method 1. Well, that's how things are supposed to

  • How to cluster Apache?

    Okay I know this isn't really a cluster apache thing (as the apache code is on the local servers volme) but I guess what I want/need to know is how do I cluster an alias on an NSS volume? So each cluster server has the Apache engine on it. I have an

  • 3G - IOS 4 locked up on backup, Instead restored. Not connecting to I tunes

    Downloaded new ITunes. Tried to install IOS4. On installation, and after 12 hrs of not completing the backup, I followed advice on a forum and did a restore. Now IOS4 is installed and working ok with just a few of my apps. Notes and contacts are all

  • Insufficient License after installing device pack

    I installed a device pack a couple of weeks ago to add support for new phones.  I am running CallManager 8.6.2.20000-2 and installed the 8.6.26154-1 device pack.  Ever since making that change, I have had a "License Warnings: System is operating on i