2 Replies Latest reply on Aug 29, 2002 11:57 AM by Dain Sundstrom

    Autogenerate of primary key fails

    Erik Turesson Novice


      I use the latest from CVS.
      I have a number of CMP 2.0 entity beans. Their primary key is autogenerated. I have one entity bean that handles the keys. I have one instance of that entity bean for each keynumber serie. When I whant to create one of the other entity beans I call the getNextKey in a session bean that calls the getNextKey method in the entity bean. This works perfectly fine when I have my application in normal service. The problem is when I execute my JUnit tests.

      I have a huge number of tests. In the setUp method I create a number of different entity beans. In the tearDown method I delete all of them. This works fine for the first testcase. However when I am creating them for the second time. My primary key generating entity bean starts to generate the same key over and over again.

      It is always the same key number that fails. I have made printouts in the getNextKey method. When entering the keyvalue is 3, retrieved with the getNumber method, then I increment it to 4, put the value using the setNumber method. Then I do a printout of what the getNumber method returns before returning the value 4. The getNumber method returns 4. But when entering this method the next time the initial value is still 3 and the generated key is 4, witch already exists.

      I think that it is very strange. It does not appear at the first generated key, it appears in the middle. It does not appear during normal execution, only during test. When I create my entity beans I have a number of for loops. This meens that I do not do anything different between the third and forth creation. The third succeds and the forth fails.

      All my methods both session and entity bean have Requires as the transaction state.

      What can be wrong?