JBoss Version : 3.2.4,3.2.5,3.2.6 We are using auto-increment fields with SQL Server and have enabled insert-after-ejb-post-create in order to support NOT NULL FK constraints.
>From a session bean, a call such as: User u = userHome.create("first","last", "[EMAIL PROTECTED]"); returns an object that is inconsistent. A call to u.getId() will return the correct auto-increment value. However, a call to u.getPrimaryKey() returns a primary key object that has the value of 0. It appears to me that the code that retrieves the auto-increment value from the sql insert statement and sets the id property value does not in turn fix the Primary Key object for the bean. For most things this is not a problem, but in addition to creating the user, we want to create an address for them at the same time. ie. User u = userHome.create("first","last", "[EMAIL PROTECTED]"); Address a = addressHome.create("street", "city", "state", u); This address create fails since JBoss attempts to use the id of 0 as the FK value. The work around we have discovered is to reload the user prior to adding the address: User u = userHome.create("first","last", "[EMAIL PROTECTED]"); //u.getId() and u.getPrimaryKey() are NOT consistent u = userHome.findByPrimaryKey(new UserPK(u.getId)); //u.getId() and u.getPrimaryKey() are consistent Address a = addressHome.create("street", "city", "state", u); This new user object is no longer inconsistent and the create of the address works as expected. Is the PrimaryKey object not being updated at the same time as the id property for a reason, or is this a bug? It seems to me that the two should be synchronized at the time the id is updated. Tas View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3861654#3861654 Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3861654 ------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user