Howdy -- Another good confusing one
The Container makes a distinction between the *entity bean* primary key and the underlying primary key in the database. The reason is that there is really *no* requirement in the spec that the actual THING the entity bean maps to (the *real* entity) is something that even HAS a primary key. So as far as the
EJB spec is concerned, the only thing that MUST have a unique primary key is the entity bean itself. That bean might map to something in a database, or even something NOT in a database, and that thing may not even have a primary key of its own (it is up to YOU to figure out how to uniquely represent it in a bean and give the bean its own primary key).
So, DuplicateKeyException is about trying to create an entity bean with a primary key that the Container sees is already in use, assuming the Container can *tell*. Now, your database may be set up in such a way that when you try to do the insert with an existing key, the database itself has a problem, but that is a separate issue.
Remember, in ejbCreate(), the Container has not yet done the insert (for CMP) -- it does the insert *after* ejbCreate(), by looking at what you've set your designated PK field to, and uses that value as the primary key to do the insert. But if the Container can already tell that your PK field value matches an entity that it knows about but which has not been removed, then you can get the DuplicateKeyException.
Also remember that you might have a primary key for your bean that is simply a composite/compound key made up of multiple field values from the *real* entity in the DB... and remember too that the entity bean might be mapped to something that doesn't look anything like a single row in a relational database, even though *most* of the time that is what we're talking about. But the spec doesn't care WHAT you store your real entities in, as long as it is something that can be considered "a persistent store".
cheers,
Kathy