2 Replies Latest reply on Jun 25, 2004 9:02 AM by Mark Frost

    Entity Bean creation question

    Mark Frost Newbie

      We have a service in a stateless session bean that must perform the following:

      1. Find an EntityBean using a known PK using home.findByPrimaryKey()
      2. If this fails with a FinderException then create the EntityBean using home.create()

      Our SLSB is defined as having transaction-type of "Bean" and we start a transaction here using SessionContext.getUserTransaction().begin()

      Our EntityBean is CMP and the SLSB is deployed to more than 1 node within our cluster.

      So the flow is:

      SLSB --> begin transaction --> findByPrimaryKey() --> if not found create() --> commit transaction

      My question is as follows:

      Is it possible that another transaction can fail to find the bean and create it, thus causing our transaction to fail at the create stage due to a PK unique constraint?

      How can we prevent this? I've read up about database isolation levels and TRANSACTION_SERIALIZABLE seems to fit the bill but it would appear to be possibly a big performance hit?

      Are there any other ways of effectively synchronizing this logic (bearing in mind we run a JBoss cluster)

      Has anyone else come across this kind of problem?

      Many thanks,
      mark