I would like to clarify my understanding of the ejbCreate/ejbPostCreate execution. If several entity beans of the same type are created in one transaction, is it allowed for the Container to execute all the ejbCreate methods first and defer the execution of ejbPostCreate to a later time? It seems that JBoss is doing that.
I noticed this behaviour using beans in a one-many relationship. For the beans on the many side, I have a unique constaint set in the database table that includes the foreign key. When creating several of those beans in one transaction, the database gives me a unique constaint violation error. This happens because the foreign key is only set in ejbPostCreate, but the database entries are already created after ejbCreate has been executed (and the foreign key is still NULL). It seems that all of the beans are first created, and the setting of the foreign key (in ejbPostCreate) is deferred until later.
Is this a bug or a feature?
It is neither a bug or a feature; it is just the way it works today.
As you have found the database row is inserted between ejbCreate and ejbPostCreate, and all updates happen at the end of the transaction. This means that JBoss currently does not support not-null foreign keys.