Retrieve new row's auto-increment key from dataprovider

** cross posted on SDN JSC Forum and Netbeans J2EE Nabble forum **
I have a page that is bound to a MySQL table rowset or, alternately, a new (append()'ed) row. The row's Primary Key is a MySQL auto-increment Integer (translates to a Long.) After commit()'ing the the new row to the database, how would I then get the new row's ID (fieldname "ID")? If I refresh() the dataprovider and try to get the value an error is thrown.
Some background: The dataprovider's backing rowset has a query parameter for the ID field. I set it to "0" if the page is creating a new row or I set it to the unique ID if the page is displaying an existing row. After the new row is committed, I need the new ID set the query parameter and synch up related rows in different tables that are keyed off the ID in this (master) table. I'd like to do this without "guessing" what the ID would be in advance as that method isn't foolproof in heavy usage.
Additionally, it strikes me as a useful workaround if the unique ID was a UUID (mySQL UUID() function) that does not run the risk of any concurrency issues. Has anyone used this solution in VWP? How would I make the call for the underying DB (in this case MySQL, but could be anything) to generate the UUID? Is the call DB specific or is there a JDBC equivalent?
UPDATE: never mind the GUID question, I can use the java.rmi.dgc.VMID class to autogenerate unique GUID's for this purpose. Being from a Lotus Notes background, I'm used to the power and flexibility such Unique ID's bring to the app. dev's portfolio.
Thanks in adv. for any help .
-Jake
Message was edited by:
jakeochs

JSF together with JBoss Seam offers some real good possibilities to improve developer productivity. Right now, with JSF you can create forms where fields are persistent (saved in a database), but you have to write code to persist fields. In Notes/Domino, every field you drop in the form is automatically set to persist without writing a single piece of code. JBoss Seam aims to provide the missing glue to tie the JSF beans with business logic (EJB) and persistent layer (JPA). I think tools for Seam are still not mature. I would love to see JSC/VWB utilizing Seam. I know there is a NetBean plugin for Seam but it was written for old NetBeans (not VWP or JSC), so it doesn't work with the visual web pack where you can drag and drop JSF components.

Similar Messages

  • MySQL Auto Increment Keys

    Is there a way to use MySQL Auto Increment Keys with Kodo?
    sean.

    Actually, I believe that the auto-increment support is in the current
    2.5.0 release (beta 2).
    -Patrick
    On Fri, 11 Apr 2003 22:11:02 -0400, Marc Prud'hommeaux wrote:
    Note that the feature isn't available in the current beta, but it will
    be available in the final release (which will be out "real soon now").
    In article <[email protected]>, Abe
    White wrote:
    I believe we've added some auto-increment support in our 2.5 beta,
    available here:
    http://solarmetric.com/Software/beta/2.5.0
    Patrick Linskey
    SolarMetric Inc.

  • Composite Primary Key or Auto Increment key ?

    Hi.. i have two ways for make something and don't know what's better ......
    Problem : 3 tables
    Client ----> ( 1,* ) Activity -----> (1,1) ActivityAccreditation
    A Client it can have one or more activities, and one Activity have one ActivityAccreditation. On Client the primary key is CLIENT_ID, the two ways for generate the keys on the other tables are :
    a ) On Activity the primary key is composed by CLIENT_ID and SEQUENCE_ACTIVITY ( a number than increment value by CLIENT_ID, example : CLIENT_ID = 1122 could have SEQUENCE_ACTIVITY from 1 to 3 for three activities, and CLIENT_ID = 1122 could have SEQUENCE_ACTIVITY from 1 to 4 for four activities ), and ActivityAccreditation have CLIENT_ID and SEQUENCE_ACTIVITY and ACCREDITATION_TYPE ( a code ).
    b) On Activity the primary key is ACTIVITY_ID ( auto increment number ) with the CLIENT_ID like foreign key only. And on ActivityAccreditation have ACTIVITY_ACCREDITATION_ID like primary key and ACTIVITY_ID like foreign key.
    The situation is than the numer of rows could to grow very much in the time ( 3.000.000 rows on ActivityAccreditation in one year and the database to be supported each five years ) and we don't know what solution is better by performance......
    Tks.

    I prefer the surrogate key.
    I don't like composite keys as a rule because they tend to inject business logic into keys. Using surrogate keys eliminates this possibility.
    For performance reasons, this means that you might want to create additional indexes on those columns to facilitate fast access. But my prejudice is to stick with surrogate keys.
    I will admit that I'm not a DBA, so there are certain to be alternative views and arguments. We'll see if any of them pop up on this thread.

  • Gets the new id of auto-increment field by jdbc

    There is a auto-increment index field of a table. I would like to add a row in that table by jdbc. The process is success and the index will increase automatically. However i would like to get the newly added index number. How can i do this? Thanks a lot.

    This is off of Microsoft's T-SQL site http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_tsqlcon_6lyk.asp
    @@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
    IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope. For more information, see IDENT_CURRENT.

  • How do I select a field and between selected rows insert auto-incremented numbers?

    I have a spreadsheet in Numbers '09 and I want to number the rows so that I can sort by the original order after I've already sorted by different items. In Excel this is fairly easy, but how do you do this in Numbers? How do I select a series of rows in a column and tell it to automatically insert numbers incremented from one to the total number of rows?
    Thanks,
    Philip

    Hi Philip,
    As an alternative to the method Yvan pointed out, you could use a formula.
    (NOTE: This takes longer to write than to do.
    (CAUTION: Make sure you use Copy/Paste Values to replace the formulas with the calculated numbers before sorting.))
    Choose a column in which to place the numbers.
    In the first non-header cell in the column enter the formula:
       =ROW()
    Select the whole column by clicking its column reference tab.
    Then use command-click to deselect the header cells above the one where you placed the formula.
    With the cell containing the formula and all of the column below it selected, go:
       Insert (menu) > Fill > Fill Down
    The formula will be filled into the rest of the column and the numbers calculated.
    With the cells still selected, COPY, then go Edit > Paste Values.
    This replaces the 'live' formulas with the numbers themselves, and prevents the numbers being recalculated when the rows are sorted.
    Regards,
    Barry

  • Calculate Row Number - Auto Increment

    I think I know what I want to do, I just don't know how to do it.
    I have a form which has rows that can be added or deleted as the user requires. The first column in the row is a control number which has some static text and a number starting at 001 that I want to add to or subtract from based on the users action of clicking on the add or delete button.
    The way I figured this would work was to place the number 1 in a hidden field on the form and att 1 to it each time the add button was pressed and/or delete 1 each time the delete button was pressed. The numbers in the remaining rows would need to be recalculated each time to ensure they are sequentially correct..
    Could anyone point me in the right direction on how to accomplish this?
    Thanks in advance for your replies. E

    Easier than that, use the "index" property in the calculate event of the field you want to number:
    $ = (concat("some_static_text", (Table1.Row1.index + 1)))
    Also regarding the hidden field, luckily this case has a property you can use already. But if you need to maintain a counter outside of your table, use a variable instead of a hidden field.
    Either add "var myVariable = null" to the initialize event of the table's subform (for a local variable) or else create a global variable in the form's properties: File > Form Properties > Variables tab.
    Either way, you can pass things to and from the variable for use in your scripts.

  • How to get auto-increment value after insert on ACCESS db?

    When you insert a new record to a table with an auto-incrementing key, how do you find the value for the row you just inserted? This works differently with different databases. I know how it's done on ORACLE and mySql.
    How does it work with ACCESS through ODBC? How about MSSQL?

    I have discovered there's a LAST aggregate function which when I've tested it gets the just inserted auto-increment, but I'm not sure if it's reliable. You have to do:
    SELECT LAST(index-field) FROM table
    That ought to be faster than MAX, which I've noticed some people use. Persumable LAST will get the value from the last row in the table's natural order.
    In fact an auto-increment field has no business filling in missing slots since the main point is a a foreign key in other tables and a foreign key pointing to a deleted table row ought to be invalidated, not point to some unrelated successor record.
    I could use a separate table as a source of counters, of course, though that's one more call. In either case I'm worried about thread safety. In Oracle there are special sequence objects for this purpose which are incremented and read atomically. I'm not sure if the access driver transaction handling works adequately.
    Perhaps the safest approach might be to use a separate sequencer table and Java sychronisation to serialise access to each row in the sequencer table (assuming all the access is from the same app).

  • Struts : creation of new row problem.

    I have a problem with creation of a new row, using struts.
    I've created simple struts browse-edit page. From browse page I go to 'edit-new' page. My object have a primary key - ID. I'm initializing it from sequence in create() method after call to super.create().
    So, when I'm forwared to 'edit-new' form from 'browse' form new row created with id taken from sequence. When I go back to 'browse' form by 'update' action it looks that another row created in View object (and onother ID is taken from sequence). Then, if I have right understanding of how it works, all attributes from first created row are copied to the second row. When ID is copied, I've got
    java.lang.reflect.InvocationTargetException: oracle.jbo.TooManyObjectsException: JBO-25013: Too many objects match the primary key oracle.jbo.Key[22 ].
         oracle.jbo.server.EntityImpl oracle.jbo.server.EntityCache.add(oracle.jbo.server.EntityImpl)
              EntityCache.java:361
         void oracle.jbo.server.EntityCache.replace(oracle.jbo.server.EntityImpl, oracle.jbo.Key)
              EntityCache.java:631
         void oracle.jbo.server.EntityImpl.setAttributeValueInternal(int, java.lang.Object)
              EntityImpl.java:2048
         void oracle.jbo.server.EntityImpl.setAttributeValue(int, java.lang.Object)
              EntityImpl.java:1844
         void oracle.jbo.server.AttributeDefImpl.set(oracle.jbo.Row, java.lang.Object)
              AttributeDefImpl.java:1688
         void oracle.jbo.server.EntityImpl.setAttributeInternal(int, java.lang.Object)
              EntityImpl.java:823
         void cern.ppt.lhc.evm.struts.UnitConversionsImpl.setId(oracle.jbo.domain.Number)
              UnitConversionsImpl.java:69
         void cern.ppt.lhc.evm.struts.UnitConversionsImpl.setAttrInvokeAccessor(int, java.lang.Object, oracle.jbo.server.AttributeDefImpl)
              UnitConversionsImpl.java:154
         void oracle.jbo.server.EntityImpl.setAttribute(int, java.lang.Object)
              EntityImpl.java:750
         void oracle.jbo.server.ViewRowStorage.setAttributeValue(int, java.lang.Object)
              ViewRowStorage.java:913
         void oracle.jbo.server.ViewRowStorage.setAttributeInternal(int, java.lang.Object)
              ViewRowStorage.java:829
         void oracle.jbo.server.ViewRowImpl.setAttributeInternal(int, java.lang.Object)
              ViewRowImpl.java:984
         void oracle.jbo.server.ViewRowImpl.setAttrInvokeAccessor(int, java.lang.Object, oracle.jbo.server.AttributeDefImpl)
              ViewRowImpl.java:961
         void oracle.jbo.server.ViewRowImpl.setAttribute(int, java.lang.Object)
              ViewRowImpl.java:753
         void oracle.jbo.html.struts11.BC4JActionForm.setAttribute(oracle.jbo.AttributeDef, java.lang.Object)
              BC4JActionForm.java:91
         void oracle.jbo.html.struts11.BC4JActionForm.setAttribute(java.lang.String, java.lang.Object)
              BC4JActionForm.java:103
         void cern.ppt.lhc.evm.struts.UnitConversionsViewForm.setId(java.lang.Object)
              UnitConversionsViewForm.java:18
         java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])
              native code
         void org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(java.lang.Object, java.lang.String, java.lang.Object)
              PropertyUtils.java:1650
         void org.apache.commons.beanutils.PropertyUtils.setNestedProperty(java.lang.Object, java.lang.String, java.lang.Object)
              PropertyUtils.java:1545
         void org.apache.commons.beanutils.PropertyUtils.setProperty(java.lang.Object, java.lang.String, java.lang.Object)
              PropertyUtils.java:1574
         void org.apache.commons.beanutils.BeanUtils.setProperty(java.lang.Object, java.lang.String, java.lang.Object)
              BeanUtils.java:919
         void org.apache.commons.beanutils.BeanUtils.populate(java.lang.Object, java.util.Map)
              BeanUtils.java:726
         void oracle.jbo.html.struts11.MultipartUtil._populate(java.lang.Object, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
              MultipartUtil.java:194
         void oracle.jbo.html.struts11.BC4JRequestProcessor.processPopulate(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.apache.struts.action.ActionForm, org.apache.struts.action.ActionMapping)
              BC4JRequestProcessor.java:417
         void org.apache.struts.action.RequestProcessor.process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
              RequestProcessor.java:246
         void org.apache.struts.action.ActionServlet.process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
              ActionServlet.java:1292
         void org.apache.struts.action.ActionServlet.doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
              ActionServlet.java:510
         void javax.servlet.http.HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
              HttpServlet.java:760
         void javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
              HttpServlet.java:853
         void com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.invoke(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
              ServletRequestDispatcher.java:724
         void com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.forwardInternal(javax.servlet.ServletRequest, javax.servlet.http.HttpServletResponse)
              ServletRequestDispatcher.java:309
         boolean com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.HttpRequestHandler.processRequest(com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.ApplicationServerThread, com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.EvermindHttpServletRequest, com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.EvermindHttpServletResponse, java.io.InputStream, java.io.OutputStream, boolean)
              HttpRequestHandler.java:767
         void com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.HttpRequestHandler.run(java.lang.Thread)
              HttpRequestHandler.java:259
         void com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.HttpRequestHandler.run()
              HttpRequestHandler.java:106
         void EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run()
              PooledExecutor.java:803
         void java.lang.Thread.run()
              Thread.java:484
    If I switch off filleng ID from the sequence everething works. It looks, that it fails, when It's coping ID (it gets two rows with the same ID).
    So, my question is - why two rows creating? And is there a way how to solve this problem, without switching off filling ID from a sequence (I really need this)?

    After reading this I am not sure what the solution is.
    I've created a VO that contains 2 EO's that are using sequence and NO trigger. I've tested this in the app module testor and it works. After using the Wizard to build a Struts/BC4J app I get the following when pressing "update" after creating a new record - "JBO-25013: Too many objects match the primary key oracle.jbo.Key[279 ]".
    Charles Gayraud suggested changing the method that sets the PK but I'm not sure what to change as there are 2 sections that deal with setting the PK, neither of which match the methods in Charles suggestion. see below
    So what is the solution here?
    Thanks,
    Bill G...
    public void setParentId(Number value) {
    setAttributeInternal(PARENTID, value);
    and
    // BG ADD
    protected void create(AttributeList attributeList) {
    super.create(attributeList);
    SequenceImpl s = new SequenceImpl("S_PARENT", getDBTransaction());
    setAttribute("ParentId", s.getSequenceNumber());
    // ParentImpl.java FULL LISTING
    package mypackage27;
    import oracle.jbo.AttributeList;
    import oracle.jbo.Key;
    import oracle.jbo.RowIterator;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.AttributeDefImpl;
    import oracle.jbo.server.EntityDefImpl;
    import oracle.jbo.server.EntityImpl;
    // bg add
    import oracle.jbo.server.SequenceImpl;
    // --- File generated by Oracle Business Components for Java.
    public class ParentImpl extends EntityImpl {
    protected static final int PARENTID = 0;
    protected static final int PARENTDESC = 1;
    protected static final int CHILD = 2;
    private static EntityDefImpl mDefinitionObject;
    * This is the default constructor (do not remove)
    public ParentImpl() {
    * Retrieves the definition object for this instance class.
    public static synchronized EntityDefImpl getDefinitionObject() {
    if (mDefinitionObject == null) {
    mDefinitionObject = (EntityDefImpl) EntityDefImpl.findDefObject(
    "mypackage27.Parent");
    return mDefinitionObject;
    * Gets the attribute value for ParentId, using the alias name ParentId
    public Number getParentId() {
    return (Number) getAttributeInternal(PARENTID);
    * Sets <code>value</code> as the attribute value for ParentId
    public void setParentId(Number value) {
    setAttributeInternal(PARENTID, value);
    * Gets the attribute value for ParentDesc, using the alias name ParentDesc
    public String getParentDesc() {
    return (String) getAttributeInternal(PARENTDESC);
    * Sets <code>value</code> as the attribute value for ParentDesc
    public void setParentDesc(String value) {
    setAttributeInternal(PARENTDESC, value);
    // Generated method. Do not modify.
    protected Object getAttrInvokeAccessor(int index, AttributeDefImpl attrDef)
    throws Exception {
    switch (index) {
    case PARENTID:return getParentId();
    case PARENTDESC:return getParentDesc();
    case CHILD:return getChild();
    default:return super.getAttrInvokeAccessor(index, attrDef);
    // Generated method. Do not modify.
    protected void setAttrInvokeAccessor(int index, Object value,
    AttributeDefImpl attrDef) throws Exception {
    switch (index) {
    case PARENTID:setParentId((Number) value);
    return;
    case PARENTDESC:setParentDesc((String) value);
    return;
    default:super.setAttrInvokeAccessor(index, value, attrDef);
    return;
    * Gets the associated entity oracle.jbo.RowIterator
    public RowIterator getChild() {
    return (RowIterator) getAttributeInternal(CHILD);
    * Creates a Key object based on given key constituents
    public static Key createPrimaryKey(Number parentId) {
    return new Key(new Object[] { parentId });
    // BG ADD
    protected void create(AttributeList attributeList) {
    super.create(attributeList);
    SequenceImpl s = new SequenceImpl("S_PARENT", getDBTransaction());
    setAttribute("ParentId", s.getSequenceNumber());

  • Auto increment sequence problem

    Hi,
    Is there any particular thing about 21st record because, when i insert data into same or different table, records start from 21 instead of 1 or where it was finished before.
    Example : I leave a table with 3 records. Come back, I insert data into same table then, auto increment starts from 21 not the 4!!!
    Thanks
    CREATE SEQUENCE FRANC_AUTOINC_SEQ
    START WITH 1
    INCREMENT BY 1
    NOMAXVALUE;
    CREATE TRIGGER FRANC_AUTOINC_TRG
    BEFORE INSERT ON FRANCHISE
    FOR EACH ROW
    BEGIN
    SELECT FRANC_AUTOINC_SEQ.NEXTVAL INTO :NEW.FRANCHISEID FROM DUAL;
    END;

    Hi,
    There's no need to do anything.
    If you want fewer numbers to be discarded in the future, you can make the cache size smaller, or remove it entirely, as in:
    CREATE SEQUENCE FRANC_AUTOINC_SEQ
    START WITH 1
    INCREMENT BY 1
    NOMAXVALUE
    NOCACHE;This may mean slightly less efficiency, since (to use my earlier analogy) you have to go to the number store and buy a new box every time you need a number, rather than going to the store once and not having to go back again until you've used up the box of twenty numbers. If you rarely use more than one new number in a session, the loss in efficiency will be insignificant.
    Regardless of the caching, if only one session is using the sequence, you will get consecutive numbers in that session. If NOCACHE is in effect, and you are the only person using the sequence, you will get consecutive numbers even if work over multiple sessions.
    Ending the session is what causes the cached numbrs to be discarded. Shutting down the database implies ending all sessions, but otherwise has nothing to do with the sequence.
    Message was edited by:
    Frank Kulash

  • Drop-down list - Global binding to addInstance of new row in Table

    Global binding - from drop-down list selection to addInstance of a new row and auto-populate the first cell of the row. Can it be done, and if so, how? Thank you.

    Me again. I also need this same functionality when the form user enters data into a text field - addInstance of a new row and auto-populate the first cell of the row. I'm assuming the same functionality? Thank you again.

  • Creating auto-increment field in SharePoint List

    In SharePoint, we can create the auto-incremental field by many ways, I am going to discuss two ways of doing it.
    Calculated field
    Item Event Receiver
    1. Using Calculated field:
    Using this we can accomplish it without doing any programing and it is a relatively simple way of doing it. By using “Calculated” column in SharePoint List we can create auto-increment field. We can accomplish this by creating a new column and choosing the
    column type as “Calculated (calculation based on other columns)”. And in Formula field, we have to enter [ID]
    In fact this will be using the values from “ID” field from SharePoint list that starts from 1.
    For example, if we want to start our auto-increment column from 100, we can modify the “Formula” field of Create New column screen, we can have to enter [ID] + 99
    For detailed info please follow the blog I wrote here: http://faisalrafique.wordpress.com/2011/03/19/creating-auto-increment-field-in-sharepoint-list/
    2. Using Item Event Receiver:
    By using this strategy, users have advantage to edit the existing values, we can also avoid it by making field read-only on feature activation. Using item event receiver, on ItemAdded event, we have to find the highest value among previously added items
    and then save the incremented value to current newly created auto-incremental column.
    For code of event reciever please follow the blog I wrote here:
    http://faisalrafique.wordpress.com/2011/03/19/creating-auto-increment-field-in-sharepoint-list/
    Happy Coding

    Use Sharepoint Designer to create a Workflow for the list containing the field to increment. For my project I had an Invoice field that I wanted to start with 1001 and increment from there so I made the following workflow to do this.
    In the new workflow screen in Sharepoint Designer create two actions in Step 1:
    Calculate Current Item:ID plus 1000 (Output to Variable: calc)
    then Set AutoIncrementNumber to Variable: calc
    This is just a guide. If you just want the auto-increment to start with 1 then you can just use this step
    Set AutoIncrementNumber to Current Item:ID
    Also, make sure you select the correct name for your field in the Workflow action instead of AutoIncrementNumber.
    Save the Workflow, close it, and then open it again in Sharepoint Designer. Check the box for "Start workflow automatically when an item is created." Save it again and then click on the Publish button to make it active on the sharepoint site. The value should
    now increment for each new item created in the list.

  • Cannot edit a field that is "Standard Report Column" when new row added

    Hi everyone,
    I have created a master-detail form from the wizard and within the detail report region source I have used apex_item.xxx API
    example;
    select C1, C2,
    CASE when C2 ='N' then
    apex_item.select_list_from_query(3, C3,'select a1 d, a2 r from table1', 'ENABLED', 'NO',null,null, 'f03_#ROWNUM#')
    else
    apex_item.select_list_from_query(3, C3,'select a1 d, a2 r from table1', 'DISABLED', 'NO',null,null, 'f03_#ROWNUM#')
    END C3
    from table;
    All columns C1,C2,C3 are defined as "Standard Report Columns".
    The results allows the column C3 field to be enabled or disabled for input depending on a condition.
    The problem is when you hit the default button "Add Row" to add a new row. The row is non-editable and is populated with null values.
    What I want is to allow input when a new row is inserted into the multi-row detail form.
    Can any one help?
    Is there a way to change the Display As field for the new row columns to "text field" from "standard report column" dynamically?

    I think you will need to use the old way of adding rows instead of the new one. I remember having headaches trying to get it working.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/otn/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Retrieving auto inc primary key from entity bean (MySQL DB)

    Hello,
    I searched the forum intensively, but did not find an answer for the following problem.
    I've set up an MySQL database "Location" with two fields (ID, Description), ID is my primary key and I've added the AUTO_INCREMENT flag to this field. This works fine, i can add a row in the table with my entity bean "Location" from my session bean :
    Location l = new Location();
    l.setDescription("at home");
    em.persist(l);
    and even when I ask this location back from the DB, there is no problem :
    Location l = em.find(Location.class,1);
    return l.getDescription();
    The rows in the table increment nicely. The problem however is, that you don't allways know the ID. So I would like to do the following from my session bean:
    Location l = new Location();
    l.setDescription("at home");
    em.persist(l);
    int id = l.getId();
    the getID method allways returns a null object. The row is added in the DB, but the auto incremented ID is not returned to the entity bean!
    I know I could solve this by generating the ID's myself, but one of the strengths of autoincrement should be not to have to do this, no?
    If anyone has a clue how to solve this issue, I would very much appreciate it !
    Michiel
    Edited by: Michiel82 on Dec 6, 2007 6:01 AM

    No reactions so far ... this is a work-around for the issue :
    I've created an additional table sequence with two fields: gen_key and gen_value. Then, in my Location entity bean I can add the following:
    @TableGenerator(
    name="locationGen",
    table="sequence",
    pkColumnName="gen_key",
    valueColumnName="gen_value",
    pkColumnValue="location",
    allocationSize=1
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE,generator="locationGen")
    @Column(name = "id", nullable=false)
    private Short id;
    This generates the primary key in the bussiness logic, but I would like to get the autogenerated key from my MySQL database (see previous post). Is this perhaps not supported by EJB3.0?
    Michiel

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • CMP with auto-increment primary key.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

Maybe you are looking for

  • Firefox downloads file as .ASPX instead of .PDF

    Trying to download Monthly Statements from Merrill Lynch website. Firefox used to download them as .PDFs (and MS IE 8 still does). Now Firefox downloads an .ASPX instead. Or maybe not -- If I change the extension of the downloaded file to .PDF. it lo

  • Add field in Z* tcode screen

    Dear All          How to add new field in Z* tcode screen Regards Suresh

  • For some reason every time I try to drag a file to desktop it opens the folder

    I have a folder that's used to just keep things for me to sort later as well. Any time I try to drag an image from chrome it's opening the folder now instead of just dropping it in. It's been doing this for the couple days, and I don't know why.

  • What's new in 8.81?

    Hi - I've seen many web casts and docs etc on what's new in 8.81 and it looks like a lot of improved functionality. Does anyone know where I can find an official SAP document to talk over with prospective clients showing them what is new? Many thanks

  • Location of the 'Folders' Component?

    Hi All, I'm trying to install the Folders component but I'm unable to figure out where it is. In the guide I'm using it says: Folders - You can find this component in the \extras directory of the Content Server 10gR3 distribution package. Make sure t