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

That catch Exception is wrong, you should be catching
PersistenceBrokerException... catching Exception is not a good thing,
and it was there because I wanted to see everything that would get thrown.

R

Robert S. Sfeir wrote:

| Thanks to everyone who helped.
|
| Some things that others might need to know if they want to do one insert
| for a full transaction...
|
| First, you don't need an auto increment row in the second table, you do
| need a primary key and a foreign key definition.
|
| Second, you can't just set the userID like I did, you have to pass the
| full bean of the first table to the second table.
|
| Third, you DON'T need anonymous access, that's a misnomer, everything
| works fine without it.  So in the end, here is what my code looks like.
| ~ I wonder if I should be on the hook to write a quick tutorial on how to
| do this.  I can do this with both ODMG and PersistenceBroker APIs now.
 :-)
|
| The Insert:
| 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.setUserInfoBean( user );
|             broker.store( userLoginBean );
|             broker.commitTransaction();
|         }
|         catch( Exception tab )
|         {
|             broker.abortTransaction();
|             tab.printStackTrace();
|             throw DataAccessException.datastoreError( tab );
|         }
|     }
|
| What fixed it: userLoginBean.setUserInfoBean(user);  is what makes it work
| What broke it: userLoginBean.setUserID(user.getUserID()) fails! it wants
| the whole user bean after insert.  (Dunno why, perhaps someone can
explain)
|
| Descriptors:
| <class-descriptor class="com.codepuccino.security.beans.UserLoginBean"
| table="CDPCNO_USER_LOGIN">
|         <field-descriptor 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-retrieve="true" auto-update="true" auto-delete="true">
|             <foreignkey field-ref="userID"/>
|         </reference-descriptor>
|     </class-descriptor>
|     <class-descriptor class="com.codepuccino.security.beans.UserInfoBean"
| table="CDPCNO_USER_INFO">
|         <field-descriptor 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="true" auto-delete="false">
|             <inverse-foreignkey field-ref="userID"/>
|         </collection-descriptor>
|     </class-descriptor>
|
| What was wrong: nothing
| What you don't need to do: access anonymous, or have an auto increment
| key in both tables, not needed.  Only in one to get the id you want to
| insert in the first place.
|
| Struts specific action simply sets the info in both beans and passes
| them down.
|
| I would not mind writing a tutorial on how to do this with both ODMG and
| PersistenceBroker.  They're both almost the same.
|
| Hope this helps someone else some day.
|
| R

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

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

iD8DBQE/urDN+cV9vuB27SARAs/jAKDzh0Y2S1vHymCtCAtXy+iJKdMm8ACggAMe
3sovd/au0Two/kaXQ42KU3Y=
=7SYs
-----END PGP SIGNATURE-----


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



Reply via email to