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?).
Which database and application server are you using?
I use MySQL 3.23-46nt and JBoss 2.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.