Discussions

EJB programming & troubleshooting: EJB primary key problem when using CMP

  1. EJB primary key problem when using CMP (1 messages)

    Hi,
    The EJB is mapped to a table which primary key is auto incremented.
    In my create() method I have to pass a PrimaryKey as a first parameter. I don't want to do that because my PK is Autoincrement and I don't know the value of the key on the last record.
    If I write my version of the create() method( and the corresponding ejbCreate() and ejbPostCreate() methods), with parameters, which doesn't include the PK(include only other non-keys columns), the problem is not solved.
    Container automatic make a Insert statement with first parameter null and throws DuplicateKeyException on the second Insert.

    Any suggestions?
    I work with Jbuilder5 and BorlandAppServer4.5

    Thanks.
  2. I have already described a solution to this problem for BMP below. CMP is the same.

    There is nothing to stop a table having multiple primary keys. If you want, you can simply ignore the autoincrementing field and use the key that you set up yourself (provided that it is a persistent primary key). Set up your finder method to use that key exclusively.