INSERT after ejbPostCreate
When a new CMP entity bean is created, the specification requires to INSERT the row in the database after ejbCreate but before ejbPostCreate invocation. If you use ejbPostCreate to change the state of the instance by, say, establishing CMR relationships among instances which, again by the specification, is not allowed to be done in ejbCreate, you will an UPDATE SQL statement after ejbPostCreate. Also it is a problem if you have NOT NULL foreign key contraints. To have only one INSERT after ejbPostCreate all you need to do is to set insert-after-ejb-post-create to true in the container configuration in jboss.xml.
Here is an example container configuration which is based on the Standard CMP 2.x EntityBean but INSERTs after ejbPostCreate:
<container-configurations> <container-configuration extends="Standard CMP 2.x EntityBean"> <container-name>INSERT after ejbPostCreate Container</container-name> <insert-after-ejb-post-create>true</insert-after-ejb-post-create> </container-configuration> </container-configurations>
Also, you must add the section in order for your EJB to use this new container:
<enterprise-beans> <entity> <ejb-name>MyBean</ejb-name> <configuration-name>INSERT after ejbPostCreate Container</configuration-name> </entity> </enterprise-beans>
Is this supported for 'cmp2.x jdbc2 pm' configuration?
Yes, it is. But the behaviour is different. I.e. this persistence manager always INSERTs after ejbPostCreate. With this configuration option you can control whether INSERT is executed right after ejbPostCreate returns (insert-after-ejb-post-create=true) or later (insert-after-ejb-post-create=false), e.g. at transaction commit time.