Solved

EJB transaction logic with locking

Posted on 2001-06-27
6
180 Views
Last Modified: 2013-11-24
Hi,

I have 2 stateless container managed transaction beans called OrderSLB and ContractSLB and one CMP bean OrderEB wrapping around an order table.

The orderslb has a method called updateOrder() defined with a Required attribute. This method does the update on the order row be looking up the OrderEB bean by findByPrimaryKey() (...besides some other operation ...)

The second bean contract bean has a method called executeContract() been defined with Required attribute. This method does 3 things
1) Check for business validity.
2)updates a status field in the order table so looks up the orderEB to do the job
3) Inserts a record in the Contract table.

The ordereb has ben set with a repeatable read serializable transcation isolation

When 2 user do a simultaneous where one does an updateOrder() and one and executeContract() I want only one user to succeed and i should be able to give an error message to the other user.  

Now i get a number of outputs when i try to do the operations simultaneously. One of them is : the updateorders() happenes first, then the update of status on the executeContract(). (note this happens between the validity check and the change of status...) Businesswise this is a bad situation. How do i prevent this ? How do i implement locking so that i know when i start the trasaction for exceuteContract() the order will not be updated

Im using Weblogic 5.1 and Oracle 8.0.6

Saba

0
Comment
Question by:sabaus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 6230702
Hacky answer, but couldn't you set a

  public static boolean flag = false ;

variable in your ContractSLB, and then set this to true when someone does an executeContract().

Then check this variable:

  if( ContractSLB.flag )
    return someError;

in your update order method...

Hmmm...might work...must be a better way of doing though...

Good Luck,

Tim.
0
 

Author Comment

by:sabaus
ID: 6234108
Its crazy ... im talking here about stateless beans how can i be gauranteed that i will be given the same bean when i check in the updateorder() method. Moreover im talking here about millions of orders being exceuted... its impossible here to track some order and flag relationship

Saba
0
 
LVL 35

Expert Comment

by:TimYates
ID: 6234798
I'm talking about a static variable...

Also, I thought EntityBeans (which I guess you are using for the db Access) implemented locking, so you won;t get to events occuring at the same time?  I thought this was the whole point...  Basically Transaction based locking...

maybe I am crazy tho
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sabaus
ID: 6236675
Its crazy doing it this way. Why should I prevent someone from updating his order when someone else's order being executed? There has to be a way of being more specfic to an order so that we can achieve an order based locking.
0
 
LVL 5

Expert Comment

by:vemul
ID: 7616537
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- To be PAQ'ed and points refunded
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7639838
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question