Try setting the UserInfo as well as the userId. I suspect OJB is nulling out the key when it sees that the UserInfo is still null. OJB will null out the id if the referenced object is null when ti goes to insert as it knows about the object relationships.

I almost always used the anonymous key feature for foreign keys just because of this. The id is really a property of the referenced object, not the parent, so I prefer to get it directly from the referenced object, and just allow the parent to have a reference to the child.

-Brian

On Monday, November 17, 2003, at 11:55 PM, Robert S. Sfeir wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am still trying to insert 2 beans into 2 separate tables, however bean
2 needs the userID from bean 1's insert.


I can't seem to find examples for this, and everything I try inserts the
first bean, seems to get the id after insert, I do a setUserID on the
second bean, then perform the insert, and I still get an exception that
user_id cannot be null. It's NOT NULL! I am pretty frustrated with
this. It should be simple, it's not. I've tried it with ODMG and with
PersistenceBroker, both return the same problem.


Further the first insert gets commited even though the transaction
commit is not called, and therefore I can't rollback any changes once
the second insert fails.

I'm using RC4.

Here is what my insert looks like:

        public final void addRegistration( final UserInfoBean user, final
UserLoginBean userLoginBean )
                        throws DataAccessException
        {
                final PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();
                try
                {
                        LOGGER.log( Level.FINEST, "Transaction open in " +
RegistrationDAOImpl.class.getName() );

                        broker.beginTransaction();
                        broker.store( user );
                        userLoginBean.setUserID( user.getUserID() );
                        broker.store( userLoginBean );
                        broker.commitTransaction();
                }
                catch( PersistenceBrokerException tab )
                {
                        broker.abortTransaction();
                        throw DataAccessException.datastoreError( tab );
                }
        }

XML:

<class-descriptor class="com.codepuccino.security.beans.UserLoginBean"
proxy="dynamic" table="CDPCNO_USER_LOGIN">
<field-descriptor id="1" name="userID" nullable="false"
column="USER_ID" jdbc-type="INTEGER" primarykey="true"/>
<field-descriptor name="loginName" nullable="false" column="USERNAME"
jdbc-type="VARCHAR"/>
<field-descriptor name="password" nullable="false" column="PASSWORD"
jdbc-type="VARCHAR"/>
<field-descriptor name="passwordReminder" column="REMINDER_CLUE"
jdbc-type="VARCHAR"/>
<field-descriptor name="statusID" column="STATUS_ID" jdbc-type="INTEGER"/>
<field-descriptor name="lastLogin" nullable="false"
column="LAST_LOGIN" jdbc-type="TIMESTAMP"/>
<field-descriptor name="baseRole" column="BASE_ROLE" jdbc-type="VARCHAR"/>
<reference-descriptor name="userInfoBean"
class-ref="com.codepuccino.security.beans.UserInfoBean"
auto-update="false" auto-delete="false">
<foreignkey field-ref="userID" field-id-ref="1"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor class="com.codepuccino.security.beans.UserInfoBean"
proxy="dynamic" table="CDPCNO_USER_INFO">
<field-descriptor id="1" name="userID" nullable="false"
column="USER_ID" jdbc-type="INTEGER" primarykey="true"
autoincrement="true" />
<field-descriptor name="firstName" nullable="false"
column="FIRST_NAME" jdbc-type="VARCHAR"/>
<field-descriptor name="lastName" nullable="false" column="LAST_NAME"
jdbc-type="VARCHAR"/>
<field-descriptor name="midInit" column="MID_INIT" jdbc-type="VARCHAR"/>
<field-descriptor name="nickname" column="NICKNAME" jdbc-type="VARCHAR"/>
<collection-descriptor name="userLogins"
element-class-ref="com.codepuccino.security.beans.UserLoginBean"
auto-update="false" auto-delete="false">
<inverse-foreignkey field-ref="userID"/>
</collection-descriptor>
</class-descriptor>


PLEASE what am I missing?  I'm going gaga here because I don't see the
problem.

R
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/uaZF+cV9vuB27SARAujIAJ9m8nJpgW5xVdN3OPb6ef9BlYSeHwCeMDUf
ob+buyLnTASop68nj+D8Tyg=
=mu+W
-----END PGP SIGNATURE-----


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to