1 Reply Latest reply on Jul 9, 2002 2:11 PM by Dain Sundstrom

    Transaction-Types, the AutoNumberBean and Relationships

    Hans Newbie

      Hi,

      I use JBoss 3.0 with MySql and Hypersonic and I use the AutoNumber-Bean for generating Ids.

      I have two entity-beans A and B where B belongs to A. (unidirectional 1-1).

      If I create the ID's manually everything works fine and the foreign key for B is inserted into A.

      If I set the transaction-type of the AutoNumberBeans to Required and if I use AutoNumberFactory.getNextInteger(..) to generate the ids in the respective create-methods no value for the foreign-key is inserted into A-table. B is inserted with the generated PrimaryKey, the same is true for A, but the foreign-key is missing.
      Everything works fine again if I set the transaction-type of the AutoNumberBean to RequiresNew.

      So it works and the transaction-type = RequiresNew is anyway the best choice I think. But why doesn't it work otherwise ? I posted this message to learn something and it might be of some help for others.

        • 1. Re: Transaction-Types, the AutoNumberBean and Relationships
          Dain Sundstrom Master

          I don't know why it is failing with Required, but you always want to use Requires New. The reason it you always want the number to increment, even if the transaction rolls back.

          Also, there is a locking issue. With Required the auto number bean will be locked until the end of the transaction. This means that your application can only create new beans in a single threaded mode (very slow).