I am using oracle. We want the equivalent of an IDENTITY or autonumber column, 
so we created views on top of our tables, and use a sequence to generate the 
primary key when an insert attempts to insert null. This works fine in SQL.

Most JDBC drivers also have some functionality that allows auto generated keys 
to be returned. Here's the error we get when we try it from JBoss.


Exception in thread "main" javax.ejb.CreateException: Primary key for created 
instance is null.
        at 
org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:574)
        at 
org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:222)
        at 
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:266)


Wouldn't it be wise for the container to attempt the insert with key return 
enabled, and then see if it gets a primary key for the object. If a proper 
primary key is returned, then update the bean, and continue. If the needed keys 
aren't returned (DB doesn't support it, schema doesn't match EJBs, etc....), 
then rollback the transaction and throw the exception just like before. 

This would allow for much more efficient insert statements, as we wouldn't
have to do one call to get the key, and a second call to perform the insert.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3872773#3872773

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3872773


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to