Transactions: Aaarrghhh! (Part 2)


EJB programming & troubleshooting: Transactions: Aaarrghhh! (Part 2)

  1. Transactions: Aaarrghhh! (Part 2) (5 messages)

    OK, enough with the philosophical murmerings, the real issue:

    Database programming from the good ol' days:

    1. Find record in table Keys where keyname = "userid"
    2. Lock record (Read/Write lock)
    3. Read keyvalue from locked record
    4. Increment keyvalue with 1
    5. Write keyvalue to locked record
    6. Unlock record
    7. ... you now have a new, unique userid ...

    The million dollar question: how do you achieve the same with Enterprise JAVA (entity beans)? After reading two books about it ("Mastering EJB II" and "Professional JAVA Server progamming"), reading every possible article on the web about EJB, I still haven't found the answer! I can't think of many database projects that wouldn't require the above functionallity, so I'm left to wonder why nobody has the answer...

    Threaded Messages (5)

  2. From one of Sun's FAQ's:

    "If a container uses only one bean instance per primary key, the container will synchronize access to the bean and therefore transaction isolation is unnecessary. Containers that use multiple instances per primary key depend on the underlying database for isolation."

    So how do you know if your container uses one or multiple instances per primary key (whatever that means)? Does JBoss use 1 or more? How about Jonas?
  3. Transactions: Aaarrghhh! (Part 2)[ Go to top ]

    You set it for WebLogic CMP in the weblogic-ejb-jar.xml file using the <transaction-isolation> element, oddly enough. The database must support the isolation level you set in the deployment descriptor before the ejb container can successfully set it. But, assuming the db does support the isolation level you are interested in, you can set it at the method level for each method in the bean.

    I can't comment on the implementations of other vendors/products.

  4. Transactions: Aaarrghhh! (Part 2)[ Go to top ]


    There have been a ton of posts on this subject in the Patterns section. Surf around there a bit and explore.

    But basically you can do exactly what you describe in your case using a SessionBean or an EntityBean. What specifically was your problem with implementing that? (outside of the fact that it isnt very scalable. In that same thread I posted some slightly modified versions of that approach that avoid the table lock contention issues).

    Dave Wolf
    The Scupper Group
    dave at scuppergroup dot com
  5. Transactions: Aaarrghhh! (Part 2)[ Go to top ]

    Yowzers that came off sounding arrogant. I didn't mean it to be :)

    Dave Wolf
    The Scupper Group
    dave at scuppergroup dot com
  6. Transactions: Aaarrghhh! (Part 2)[ Go to top ]


    There is a session bean and entity bean from opensymphony in there oscore package that will create a primary key for each EJB. You simple give it the class name of your bean and it creates and entry in table that is implemented by their session/entity beans.

    Works well and as the key is a row in the database represented by an entity bean the EJB container should handle the concurrent updates.

    Owen Fellows