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

Similar Messages

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

  • 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

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

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

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

  • Cannot install windows 7 on brand new mac mini with 256 g sdd? Please help.

    Cannot install windows 7 on brand new mac mini with 256 g sdd? Please help.
    Have tried all tricks found on the net and followed every advice from apple support.
    Still black screen with blinking curser when mini is rebooting following partitioning via bootcamp.
    Very nice and fast mashine, wouldnt like to return it.
    thanks allan

    Is that an Apple SSD?
    what model is it?
    Is there a firmware update if non Apple?
    Lion is not server version.
    Windows is ? ISO or retail?
    Google macmini Windows 7 SSD Apple Boot Camp

  • HT2953 i-tunes could not be used because the original file could not be found.could not locate.this error occurs on most of my songs in my library and will not play even though they are in my i-pod and play with no trouble.can  anyone please help?

    i-tunes could not be used because the original file could not be found.could not locate.this error occurs on most of my songs in my library and will not play even though they are in my i-pod and play with no trouble.can  anyone please help?

    I was not complete clear.
    Since you never changed the settings in the advanced section of iTunes preferecnes, you have to chech that your music is really in the location setted in the folders reported in the advanced section.  If not you have 2 ways: reset the position of this folders or in the actual disk organisation or in the pointing on the preferences.
    If you press the reset button you just give to itunes its default setting as for the position of the music files: probably this will be a good choice if you have never changed any default preference.
    But before I would check the folders and see if the songs are really there
    In my iTune I have this, and I believe it is the default.
    Users/YOURHOMEFOLDERNAME/Music/iTunes/iTunes Music

  • Hi, All. Iam using Adobe Document Cloud. After saving a pdf document to this cloud, I am able to see my PC folders . How to disable this? Does my PC folders are also available across other PC's to access them with my Adobe ID? Please help me. Thanks

    Hi, All. Iam using Adobe Document Cloud. After saving a pdf document to this cloud, I am able to see my PC folders as well with a browsing option  . How to disable this? Does my PC folders will  also available across other PC's to access them with my Adobe ID? Please help me. Thanks in advance.

    Hi indi68632954,
    I can understand your concern & you need to worry about this, as your PC folders won't be available on other PC's as this option is just to browse through the files of the specific system on which you are working as shown in the screenshot below.
    Only the files uploaded on the Document cloud will be available over Internet using Adobe Document Cloud service upon the authentication of your Adobe ID & password.
    I hope this will answer your query.
    In case if you have any further query please let us know, we will be happy to assist you.
    Regards,
    Aadesh

  • My iPad 2 won't receive text messages and is not sharing any data with my iPhone 4. Please help!

    My iPad 2 won't receive text messages and is not sharing any data with my iPhone 4. Please help!

    The iPad receives Text Messages through Apple's iMessage feature. Make sure this is turned on on your phone. Also, text messages received at your phone number are not shared with the iPad. Make sure that iMessage texts are being sent to your EMAIL ADDRESS

  • TS1424 err = 3150 - this issue has started recently and continues to persist with all of my downloads - please help

    err = 3150 - this issue has started recently and continues to persist with all of my downloads - please help

    Is it error 3150 or -3150 ? If -3150 then have you tried the troubleshooting for that error number on this page : http://support.apple.com/kb/TS3297 ?
    "Error -3150"
    This alert is often related to a lost connection to the iTunes Store.
    If you encounter this alert and you have verified you have a connection to the Internet using Wi-Fi, please review AirPort and Bluetooth: Potential sources of wireless interference.
    If the issue persists, and you're using iTunes for Windows, you may need to flush your DNS and remove pop-up or ad-blockers.
    Finally, this can occur due to timeouts caused by security software.

  • Anyone know setting primary key deferred help in the bulk loading

    Hi,
    Anyone know by setting primary key deferred help in the bulk loading in term of performance..cos i do not want to disable the index, cos when user query the existing records in the table, it will affect the search query.
    Thank You...

    In the Oracle 8.0 documentation when deferred constraints were introduced Oracle stated that defering testing the PK constraint until commit time was more efficient than testing each constraint at the time of insert.
    I have never tested this assertion.
    In order to create a deferred PK constraint the index used to support the PK must be created as non-unique.
    HTH -- Mark D Powell --

Maybe you are looking for

  • Exchange email will not work when offline

    Anyone know when Apple will fix this issue?  Email will not work correctly unless connected to wireless.  This makes it impossible to be productive while flying.  This is exclusive to exchange servers as it woks on POP accounts.  

  • MacBook pro RAM to new iMac ???

    G'day, Does anyone know if MB Pro RAM is compatible with the new iMacs. I know it is with the previous iMac's, but I can't find out off the OWC Wesite??? Cheers.

  • Embed a QT mov or Drag & Drop a QT mov?

    Hi, I'm wondering that which is the best way to put in a Movie into iWeb? Embed a QT mov or Drag & Drop a QT mov?is both are the same thing?

  • Photoshop CS6 not printing

    Photoshop gives me this message when I try to print from my iMac: There was an error opening your printer. Printing functions will not be available until you have selected a printer and reopened any documents. I've deleted and reinstalled my printer.

  • Help xsql

    I have a big problem, this is the result when I try to run the demo of ORACLE XSQL Servlet (1.0) under Apache Jserv. My db is oracle8i Enterprise Edition. XSQL-007: Cannot acquire a database connection to process page. Eccezione IO: Connection refuse