How to code the ejbCreate() method without initailizing primary key?

Hi all,
I've just started learning about EJBs, and now am at the stage of learning how to create, deploy and test a CMP Entity Bean.
Ran into a problem which I'm hoping someone can help out with.
I'm using SQL Server 2000 as my backend database, and have created a simple table called TEST with 2 fields, id and name. id is set as the primary key, and as an identity conlumn. What this means is that when we do inserts, we don't need to specify a value for the id column. SQL Servers automatically generates that value.
Here's my ejbCreate method in my bean class:
public Integer ejbCreate(String name) throws CreateException {
    this.setName(name);
}When I tried to run the create method from a web client, I got this error:
javax.ejb.CreateException: [EJB:010148]In EJB 'SampleEJB', the primary key field 'id' was not set during ejbCreate. All primary key fields must be initialized during ejbCreate. at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:186) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244) at everbright.ejb.SampleEJB_uzc4wg_HomeImpl_813_WLStub.create(Unknown Source) at jsp_servlet.__index._jspService(__index.java:152) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
So it seems like I can't leave the id field uninitialized in the ejbCreate method. However I don't know what to initialize it with either, because in order to know what value I need to initialize it to, I'll need to run a db query to retrieve the next primary key value for the id field. This doesn't sound very efficient to me.
I tried to initailize it to null, but that gave me a NullPointerException.
Why do we need to initialize the primary key field in ejbCreate? Should the container do the insert and then get it from the table accordingly?
Is there any other way I can get this set-up working?
Thanks!

Hi Fusion777,
Ya, I've been searching around forums for an answer also. Apparently this is indeed a problem that has no general solution. It depends on 2 factors:
1) Whether or not the database supports autogenerate key (which most does) and how (Oracle does it by sequences while SQL Server by identities)
2) Whether or not the application server supports 1).
In my case, I'm using SQL Server and Weblogic Server 8.1 and most fortunately, Weblogic does support identities and sequences. Just define the <auto-key-generation> stanza in your weblogic-cmp-rdbms-jar.xml deployment descriptor, as follows:
<automatic-key-generation>
     <generator-type>ORACLE</generator-type>
     <generator-name>test_sequence</generator-name>
     <key-cache-size>10</key-cache-size>
</automatic-key-generation>
<automatic-key-generation>
     <generator-type>SQL-SERVER</generator-type>
</automatic-key-generation>
<automatic-key-generation>
     <generator-type>NAMED_SEQUENCE_TABLE</generator-type>
     <generator-name>MY_SEQUENCE_TABLE_NAME</generator-name>
     <key-cache-size>100</key-cache-size>
</automatic-key-generation>I've tried that and it works :-)
I gather from your reply that those who are using JBoss are equally fortunate :-)
So I thought I'll share this in case some other poor fellow is facing the same problem as we are. At least worse come to worse, he'll have the option of switching to either JBoss or Weblogic and know that it works in both :-)
Some other users seem to be against the idea of using auto-generated keys for precisely the reason that it is not a standard across database and application servers. See this thread:
http://forum.java.sun.com/thread.jspa?forumID=13&threadID=329896
I've in fact stopped working on EJB 2.0 and am exploring something called Hibernate, which seems to have a more generic way of dealing with the auto-generated key issue. In fact, I've heard news that EJB 3.0, which is the upcoming standard for EJB, will be heavily inspired by Hibernate as far as CMP Entity Beans are concerned.
You can check out Hibernate at http://www.hibernate.org.

Similar Messages

  • How to change the source type for a primary key on a form?

    Hi,
    At the time of creating a form, I had set the source type for the primary key to an existing sequence.
    Now I want to change the source to a trigger.
    Can anyone suggest how to do it?
    Thanks in advance,
    Annie

    Annie:
    Define the trigger and then delete the page process named 'Get PK'
    Varad

  • How To Code the I_CALLBACK_USER_COMMAND   = 'USER'  in HR-ABAP

    Dear Friends,
    How to code the I_CALLBACK_USER_COMMAND   = 'USER'  in Reuse_Alv_Grid_Display  in HR-ABAP

    This is one method of programming the user_commend
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program      = g_repid
          i_callback_user_command = 'USER_COMMAND'
          i_callback_top_of_page  = 'TOP_OF_PAGE'
          i_structure_name        = 'I_DATA'
          is_layout               = gs_layout
          it_fieldcat             = gt_fieldcat[]
          it_sort                 = gt_sort[]
          i_save                  = 'A'
          is_variant              = es_variant
          it_events               = gt_events[]
          is_print                = gs_print
        tables
          t_outtab                = i_data
        exceptions
          program_error           = 1
          others                  = 2.
    *& USER_COMMAND
    *& This form is called through Function 'REUSE_ALV_GRID_DISPLAY'.
    *& If you are in detailed mode then transaction PA20
    form user_command using r_ucomm like sy-ucomm
                            rs_selfield type slis_selfield.
      case r_ucomm.
        when '&IC1'.
          check rs_selfield-sel_tab_field = 'I_DATA-PERNR'.
          read table i_data  index rs_selfield-tabindex.
          set parameter id 'PER' field i_data-pernr.
          call transaction 'PA20'.
        when others.
      endcase.
    endform.                    "user_command

  • How to view the sapscript result without directing to Printer

    Hi All,
    I am new to ABAP. can any one tell me how to view the sapscript output without redirecting to the printer from an abap program.
    Help would be appriciated.
    Thanks,
    hima

    There are several ways you can view the output of the SAPscript, without redirecting it to the printer.
    1. You can directly view the output  using Menu --> Utilities -->  Printing Test --> give the default printer as LP01  and click Print Preview button, that should give you the print preview of the SAP Script.
    2. You can execute the the driver program, if it is a custom program (Z program)  then execute the program, it will give you an option of selecting printer,, give the printer as LP01 and select print preview.
    lets say you are trying to view the purchase order "Zmedruck", the driver program for the same can be found using the transaction code NACE. or else you can execute the transaction code ME23N, There you will find a button called "Print Preview"  Click that to preview your SAP Script. Menu --> GoTo --> Print Preview.
    Similarly you will find options to view your sap script in almost all the standard transactions where you are using your SAP Script.
    If you need further information,, give me a mail at [email protected]
    if found useful, don't forget to reward points.
    Thanks-
    Shrikant

  • How to use the index method for pathpoints object in illustrator through javascripts

    hii...
    am using Illustrator CS2 using javascripts...
    how to use the index method for pathpoints object in illustrator through javascripts..

    Hi, what are you trying to do with path points?
    CarlosCanto

  • How to use the POST method In Oracle APEX 3.1

    Hi,
    In APEX if we are submitting the page the parameters( Variables ) will pass through URL.
    How to hide the these parameters from URL??
    I Hope POST method will solve this problem.
    How to use the POST method in APEX???
    Help me out to solve this problem.
    thanks in advance.
    Cheers,
    Shan

    In APEX if we are submitting the page the parameters( Variables ) will pass through URL.No they won't. Submission POSTs the <tt>wwv_flow</tt> form.
    Sometimes a branch may be performed after submission, generating a URL in which parameter values are visible. To avoid this, use the save state before branching option.
    Other actions&mdash;like using navigation lists, or clicking a link in a report&mdash;will perform a GET using parameters in the URL. In these cases using Session State Protection is advised.

  • How to know the class method behind an enterprise service

    Hi,
    SAP has provided enterprise services for Room booking in Real Estate module. They are even shipping the complete application for a nominal price. But the standard version is not suitable for our client requirement so they want to develop this application inhouse.
    Now my question is:  I know the enterprise services used in this application. How to know the implementing methods behind these enterprise services ?
    If possible suggest which approach will be a better option for the inhouse development.
    1. Webdynpro ABAP and use directly methods behind the enterprise services.
    2. Webdynpro ABAP and create client proxy class for the enterprise services.
    3. Webdynpro JAVA and use the enterprise services.
    4. Using visual composer modelling the application.
    Please suggest the best alternative.
    Best Regards,
    Aleem Mohiuddin.

    Hi
    They are even shipping the complete application for a nominal price. But the standard version is not suitable for our client requirement so they want to develop this application inhouse.
    I assume you are talking about xApps.
    How to know the implementing methods behind these enterprise services ?
    In sproxy transaction you can search service and then you can see class and method implemented behind that particular service.
    1. Webdynpro ABAP and use directly methods behind the enterprise services.
    In my opinion not recommended to bypass ES and use method behind it.
    2. Webdynpro ABAP and create client proxy class for the enterprise services.
    Not sure why you want to create proxy of ES.
    3. Webdynpro JAVA and use the enterprise services.
    4. Using visual composer modelling the application.
    You can use either Webdynpro (ABAP or Java) or VC to model your application which consume ES in backend. Both options are good, you can chose Java or ABAP flavor of dynpro based on skill available in team. VC is very effective in rapid modelling and can be used in protyping or in development of complete application.
    Regards,
    Gourav

  • I have an apple emac powerpc G4 which is running 10.3.9 software. I downloaded the 10.5 leopard software. Does anyone know how to install the 10.5 without using the dvd installer? In dummy terms please?

    If any one could help me with this. i'd be enternally grateful as i'm getting nowhere on my own!
    I have an apple emac powerpc G4 which is running 10.3.9 software. I downloaded the 10.5 leopard software. Does anyone know how to install the 10.5 without using the dvd installer? In dummy terms please

    The only way to get 10.5 is to purchase it on CD. Such as http://www.amazon.com/Mac-OS-Leopard-10-5-10-51/dp/B0012RAVRC where is being sold for $179.99.
    If your optical drive is broken, you will either need to replace it or get an external. There is no other way.
    Why do wish to upgrade? As you can see it is going to be expensive, probably more the Mac is worth.
    Allan

  • QM Module - How to get the Inspection Method & Characteristic value(Urgent)

    Hi All,
        I have inspection lot number (PRUEFLOS), batch number 
       (CHARGE), plant (WERK) & material number
       (MATNR) , using these fields how to get the inspection
       method (PMETHODE) & Characteristic Value (ATWRT) ?
       I don’t know the relation among them.
    Could you please help?
    Thanks in advance.
    Saket

    Hi Jose,
    Thanks for your help, could you please look into my requirement.
    For all inspection characteristics listed in the selected COA profile, I have to retrieve the Inspection Method for all listed inspection characteristics. And also I have to retrieve the characteristic value(uncertainty). Additionally, for inspection characteristics that are quantitative, being checked, the characteristic value(uncertainty) from that Inspection method will be retrieved from class 3050_UNCERTAINTY, class type 006, characteristic, P2150_UNCERTAINTY. 
    Please help me out.
    Thanks,
    Saket .

  • How to access the remote Objects Without Db_links?

    Hi ,
    I want to know how to access the remote objects without db_link.That is i want to access a object in some other server which has different database.

    SanjayBala, just so you know that it is possible to create a database link in Oracle to non-Oracle databases in some circumstances. Look up Generic Connectivity aslo know as Heterogenous Services. With 11g Oracle has basically renamed the feature and replaced it with somethinkg named ike DG4ODBC.
    I have not spent time studying the details for DB4ODBC but with HS Oracle provided the interface and you had to obtain the necessary ODBC driver on your own. I had Oracle on AIX reading and writing to SQL Server on Windows but the developers chose to write a java program and connect to both via it. On Windows and Linux platforms the necessary ODBC drivers might be available without the requirement to go out and purchase one.
    The Oracle Open Gateway product is an advanced version of the above features with drivers for specific non-Oracle databases included like DB2 or Informix.
    HTH -- Mark D Powell --

  • How to have the Chat history without the Exchange server?

    How to have the Chat history without the Exchange server?

    Hi,
    You can try Archiving server. Archiving is the storing of IM and conferencing data in an SQL backend database. This data is not instantly readable / searchable. The Lync users are not able to read it directly. The admin can export the data using Lync powershell
    and then convert it into a readable format.
    Kent Huang
    TechNet Community Support

  • How to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method.

    how to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method.  thanks

    INSERT targetdb.dbo.tbl (col1, col2, col3, ...)
       SELECT col1, col2, col3, ...
       FROM   sourcedb.dbo.tbl
    Or what is your question really about? Since you talke about foreign keys etc, I suspect that you want to transfer the entire table definition, but you cannot do that with an INSERT statement.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • HT1918 Created an apple I'd using a wrong e-mail address. Can't access the e-mail to varify the Apple ID in order to be able to change the account settings. Any idea how can change the account information without having to varify the account through the e

    Created an apple I'd using a wrong e-mail address. Can't access the e-mail to varify the Apple ID in order to be able to change the account settings. Any idea how can change the account information without having to varify the account through the e-mail?

    You are trying to find a loophole to circumvent a basic rule that prohibits the transfer of purchased content from one Apple ID to another.
    Content tied to an Apple ID are bound to that Apple ID forever. You can not merge or trade accounts. Well, not (officially) anyway...

  • How to code the function of  add+delete+edit using jsp??

    how to code the function of add+delete+edit using jsp??i'm also using the ms sql server 2000 as a database. pls help me!!

    Hi,
    I think you will find the following useful.
    Performing Inserts, Updates, and Deletes
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/inserts_updates_deletes.html

  • I accidentally deleted all my apps and music. I can re-download the music but don't know how to get the apps back without buying them again. Any thoughts?

    I accidentally deleted all my apps and music. I can re-download the music but don't know how to get the apps back without buying them again. Any thoughts?

    Just follow this:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

Maybe you are looking for

  • SAX parser and EntityResolver

    I am using the sample SAXSample.java that comes as part of the XML parser download to parse an XML file that contains references to external entities - for example <!ENTITY E23678 SYSTEM "http://pilot/:13365"> However the SAX parser never appears to

  • If PO is created Or approved   reference PR,  should not allow to change th

    Dear All I have one requirement If PO is created Or approved   reference PR,  should not allow to change the quantity or line item. And is it possible to assign this to user specific whether to allow or not . Thanks in advance Mahisap

  • Not all photos in photostream are pushing

    Hi, I thought I had everything set up properly. I have had pics build up in my photostream. As of right now, there are over 600. I am not sure I downloaded them all, but they are not appearing in the photostream folder in my computer. How do I get th

  • Creating a web page

    i m beginer to java. i want help to create a web page having login tag and password tag and few menus. these menu must be activated after login

  • Trouble with digital copy

    I received a message from iTunes that an error occurred while transferring my movie from digital copy. The movie does not show up on my iPad under purchased.