Discussions

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

  1. EJB primary key problem when using BMP (3 messages)

    Hi,
    I am new to EJB and I've just encoutered to a small problem when implementing an entity EJB. The EJB is mapped to a table which primary key is auto incremented.
    In my ejbCreate method I put an primary key, but the real key stored in db is different.
    The problem is that I set the primary key property of the bean to the wrong id. The only prossible way seems to make a SQL query just after SQL insert to obtain the real primary key.
    But this kind of way seems to me to be a hack.
    Is there another way (nice) how to do it? (a container setting or something like it?).

    Thanks.
  2. Which database and application server are you using?
  3. I use MySQL 3.23-46nt and JBoss 2.4.4 .
  4. 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 methods to use that key exclusively.