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.

Similar Messages

  • 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

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

  • 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

  • Failure to create entity bean with CMP2 under JBOSS + Postgresql

    I have written a simple jsp programme using JBOSS 4 DR2 with postgresql 7.3.3 whereby a simple entity bean could be created into a table in the postgresql 7.3.3 table. However I kept getting the exception message [ javax.ejb.CreateException :Erro checking if entity exists:java.sql.SQLException: ERROR:parser:parse error at or near "=" at character 39 ]
    I have even examined the logfile created under the cygwin postgresql , the log output record produce the error FATAL : unsupported frontend protocol ,with next line read [ERROR:parser:parse error at or near "=" at character 39 .
    I have no idea why this is happening? The postgrsql 7.3.3 was run under cygwin using the command: pg_ctl start _D {data directory} -l logfile -o "-p 5432"
    My guess is that this may not be the Jboss-postgresql data source configuration error since I am able the verify the existence postgresql jndi ,datasource and connector service under the jboss console.Somehow it just got something to do with the jsp programme in the way it was written may be ? But it should not pose a great problem, since i am trying to create a simple entity bean only.
    By the way the entity bean creation statement is home.create("123"),to further verify that the home & remote interface was working ,I have the object context printed out before the creation, and it appeared OK.
    Thanks in advance for those willing to help me to resolve the issues

    I have managed to get the debug from the postmaster , it all boils down to the query [SELECT COUNT(*) FROM {TABLE} WHERE ={CMP FILED}="123"] , the = sign after the 'WHERE' responsible for the failure , but I am still puzzle why it would happen as such?
    Any helper ?
    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.

  • Do I need to Create Primary Key Class for Entity beans with Local interface

    Do I need to Create Primary Key Class for Entity beans with Local interface?
    I have created my entity bean with the wizard in Sun One Studio and it does not create a primary key class for you.
    I thought that the primary key class was required. My key is made up of only one field.
    Anyone know the answer.
    Jim

    u dont need to create a primary key class for a entity bean.if ur table's primary key feild(int ,float) is a built in or primitive data type,then u dont need one.But if ur table has a primary key field which is non primitive (for example StudentID,ItemID etc)then u have to create a primary key class.
    hope this helps :-)

  • Entity bean with primary key generated by trigger

    Hi,
    We have a table(oracle) with one column as primary key,
    but the primary key is generated by trigger every time
    a new row is inserted into this table, inside the trigger,
    it uses oracle sequence to get the next val.
    If we want to use entity bean with it, what should we specify, it's not application-managed primay key, it's
    not auto-generated primary key either. How can we resolve
    it without change the database part.
    Any thought is appreciated.
    Thanks
    afang

    The code is already there with JDBC call inserting
    into the table, the inserting trigger then will generate
    sequence key and being inserted into primary key column.
    Now wondering if it's possible to change the code to use entity bean but without modifying the trigger (since it contains other business logics).

  • 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

  • Did elationship fields in entity bean with CMP same as foreign key in table

    did elationship fields in entity bean with CMP same as foreign key in table database.so we don't have to make some foreign key column in table database.
    did Container handle that both.
    I need some answer
    thank's

    Suppose you have Group and user entity. Relation is 1-m. One group many users. When you create user, you dont need to send group id, All you need is create user and add it in collection (cmr-field) in group(user belongs to). Container will add its group id in user entity as well as in db.

  • Multiple users accessing entity bean with same PK

    Hi,
    Some body please clarify the below issue.
    (EJB 1.1, WAS3.5)
    I have two app servers and two clones each clone is running in each app server.
    Stateful session bean access Entity beans to update/read record in the database.
    According to my requirement multiple users can access the same entity data (same primary key). Suppose user A created a Stateful session bean SB1 and the SB1 created Entity1 with PK1, this is happening at clone1.
    User B accessed the site and the request went to Clone2 and a new SB2 created, but the SB2 need to access the database with Same PK1.
    For the above situation, I guess container can not create a new Entity bean with PK1 because EB with PK1 is already there and it tries to allocate same EB1 with SB2, so if two requests are concurrent do the SB2 wait to get the handle of the EB1?
    Is there any way to create two Entity beans with same Primary Key at the same time but in different clone?
    Thanks,
    Sagar

    Hi,
    The concurrency level has to be set at the level of database and the database will take care of consistency & integrity of the data. So specity the concurrency level on the database connection in each appserver.

  • MDB gets cannot find recently created Entity Bean

    I have a session bean that creates several entities beans, and puts a message onto
    JMS queue. A MDB is configured to read the queue, and in onMessage(), it calls
    findByPrimaryKey() for one of the newly created EntityBeans. However, the entity
    bean cannot be found.
    All of the beans in question are using container managed transactions, and all
    have transaction required. The entity bean that I'm looking for is using optimistic
    concurrency. I cannot change it to exclusive without redesigning a major part
    of the system, which have solved a similar problem that I encounted earlier that
    did not involve any message driven beans.
    The only way that I got it to work is put in Thread.sleep(5000) right before calling
    the finder. Does anyone know of any alternatives besides having the MDB sleep?

    No, this will work fine with the existing server. If the publish is
    part of the JTA transaction, then no one can consume the message until
    the original JTA transaction has committed.
    -- Rob
    Rajesh Mirchandani wrote:
    XA defines that a transaction's individual operations will either fail or
    succeed atomically. XA can not, and does not define that a transaction's
    individual operations occur exactly simultaneously.
    The WL transaction monitor does not currently provide a way to serialize a
    transactions commit operations on its component resource managers.
    There is an enhancement filed for this, I guess. Follow up with BEA support.
    Rob Woollen wrote:
    Vina Wang wrote:
    The JMS send is part of the transaction, sort of. The call is within
    the session
    bean transaction, but I'm not using transacted session for
    JMSPulisher. Would
    that fix the problem?Sadly this is a confusing aspect of JMS. You want a non-transacted
    session because you want it to participate in the global transaction
    that the EJB started. Also, make sure that you've enabled user
    transactions on your connection factory.
    There's more info here:
    http://edocs.bea.com/wls/docs70/faq/jms.html#252635
    Let us know if you're still having problems.
    -- Rob
    I know that the transaction hasn't been commited, but I was monitoring
    database
    via SQL call when I tried this. There was about 2 second delay on my
    development
    machine.
    Rob Woollen wrote:
    My guess is the MDB is receiving the message before your "create entity
    bean" transaction has committed. Is the JMS send part of the "create
    entity bean" transaction? It probably should be.
    You can easily prove this by writing a few lines of JDBC to hit the
    database and check for your primary key.
    I would not recommend changing to exclusive or using the Thread.sleep.
    -- Rob
    Vina Wang wrote:
    I have a session bean that creates several entities beans, and putsa
    message onto
    JMS queue. A MDB is configured to read the queue, and in onMessage(),
    it calls
    findByPrimaryKey() for one of the newly created EntityBeans. However,
    the entity
    bean cannot be found.
    All of the beans in question are using container managed transactions,
    and all
    have transaction required. The entity bean that I'm looking for is
    using optimistic
    concurrency. I cannot change it to exclusive without redesigning a
    major part
    of the system, which have solved a similar problem that I encounted
    earlier that
    did not involve any message driven beans.
    The only way that I got it to work is put in Thread.sleep(5000) right
    before calling
    the finder. Does anyone know of any alternatives besides having the
    MDB sleep?
    Rajesh Mirchandani
    Developer Relations Engineer
    BEA Support

  • 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

  • Is it possible to map the cmp fields of the entity bean with out dictionary

    Dear sirs,
    I have created the EJB project module and WEB Module. Now i have to map the CMP fields of the entity bean to the underlying table. Is it possible to map the cmp fields of the entity bean with out java dictionary? If yes how can we do that.
    I have got some error while mapping an EJB's CMP fields to the table through dictionary. I was actually intended to map 79 fields but it gives an error that more than 64 fields are not allowed while building the dictionary.
    1. Can you tell me what could be the possible reason?
    2. Is it possible to map the cmp fields of the entity bean with out java dictionary? If yes how can we do that.
    Kindly helo me,
    Sudheesh K S

    Hi,
    Sudheesh please check up if the below link helps,there are other ways of writing the persistent.xml for container managed entity bean.
    http://help.sap.com/saphelp_nw04s/helpdata/en/9b/f695f0c84acf46a4e0b31f69d8a9b7/frameset.htm, probably in the studio you cannot browse through tables not in  the java dictionary,but manually editing it may still solve the problem.
    Also here is another link that specifies the databases supported by J2EE Engine.
    http://help.sap.com/saphelp_nw04s/helpdata/en/66/a5283eeb47b40be10000000a114084/frameset.htm
    The below link shows how to specify the database vendor and datasource
    http://help.sap.com/saphelp_nw04s/helpdata/en/e1/67fc3ee241ba28e10000000a114084/frameset.htm
    Hope you are able to solve the problem.
    Do let us know if you come up with the solution.
    Regards,
    Harish
    Message was edited by: HARISH SUBRAMANIAN

  • CMP Entity Bean with ejb-ql finder methods and INFORMIX database

    Hi,
    I have some CMP Entity Beans with finder methods defined in ejb-ql. In my ejb-jar, within <entity> definitions I have something like:
        <entity>
          <abstract-schema-name>BeanName</abstract-schema-name>
          <cmp-field><field-name>fieldOne</field-name></cmp-field>
          <cmp-field><field-name>fieldTwo</field-name></cmp-field>
          <query>
            <query-method>
              <method-name>findAll</method-name>
              <method-params></method-params>
            </query-method>
            <ejb-ql>SELECT OBJECT(o) FROM BeanName o</ejb-ql>
          </query>
        <entity>
    And in persistent.xml:
    <db-properties>
         <data-source-name>datasource_name</data-source-name>
    </db-properties>
    <entity-bean>
         <ejb-name>BeanName</ejb-name>
         <table-name>table_name</table-name>
         <field-map key-type="NoKey">
         <field-name>fieldOne</field-name>
         <column><column-name>column_one</column-name></column>
          </field-map>
         <field-map key-type="NoKey">
         <field-name>fieldTwo</field-name>
         <column><column-name>column_two</column-name></column>
          </field-map>
          <finder-descriptor>
              <method-name>findAll</method-name>
              <method-params/>
         </finder-descriptor>
    Once deployed, on server side, I can found a java source file (with corresponding compiled class file) in path:
    j2ee/cluster/server0/apps/companyName/MyEARApp/EJBContainer/temp/temp38837373733/route/to/package/
    with names:
    BeanName0_0pm.java
    BeanName0_0PM.class
    and the generated java file contains this code:
      public java.util.Enumeration ejbFindAll() throws javax.ejb.FinderException, javax.ejb.EJBException  {
        TransactionContext tc = pm.getTransactionContext();
        Connection conn = null;
        PreparedStatement pSt = null;
        ResultSet ejb_rs = null;
        int status = javax.transaction.xa.XAResource.TMSUCCESS;
        try {
          conn = pm.getConnectionForFindMethod();
          pSt = conn.prepareStatement("SELECT \"O\".\"COLUMN_ONE\",\"O\".\"COLUMN_TWO\", FROM \"TABLE_NAME\" \"O\"");
          ejb_rs = pSt.executeQuery();
    I'm trying to call this method but it throws a SQLException when preparing the statement.
    It seems that Informix does not like this SQL syntax because of upper case names, doble quotes on table alias, or something else.
    When editing persistent.xml in netweaver, I can define the element <datasource-vendor> as ORACLE, SAPDB, MS_SQL_SERVER, DB2_UDB_AS400 or DB2_UDB_OS390 but INFORMIX is not an accepted value.
    Is there any way to define how this SQL query is build?
    Thanks in advance.

    The return type of the finder method defined in the remote home interface is either the entity bean's remote interface or a collection of objects implementing the entity bean's remote interface. The return type of the finder method defined in the local home interface is either the entity bean's local interface or a collection of objects implementing the entity bean's local interface

Maybe you are looking for