I have an interesting ejbLoad and ejbStore problem. I have a number of
session and entity beans deployed, all entity beans are bean managed. It's
the age old shopping mall thing. So essentially I have a Customer session
bean with a buy method. The buy method starts a transaction - I manually
control the transactions. Everything works great, correct amounts are
credited and debited, transactions are begun and committed.

While testing, the customers account ran out of money, so I manually
increased the balance using SQL Plus, we are using Oracle. I did remember to
commit my update in SQL Plus (I have learnt my lesson). I then ran my test
program again and kept getting an insufficient funds exception even though I
had just updated the account balance manually. I finally figured out the
following was happening.

I did an ejbFind( ) which returned a new Account entity bean with the
correct updated balance, which I had just updated in SQL Plus. jBoss then
went and did an ejbStore() with an old Account bean instance in the pool,
which had the old Account balance, and which then reset the balance. 

If the previous transaction committed successfully why does the container
(jBoss) do an ejbStore. I should rather do an ejbLoad() or nothing at all. 

If I shutdown and restart jBoss there are no 'rogue' beans out there to
'mess things up', obviously, and everything works fine. What am I doing
wrong? I undestand transaction isolation can be quite complex. Do I need to
set a transaction attributes for each method in my entity beans?

The debug output from jBoss and my code is... as you can see the Balance
should be 60 but is reset to 5

[InternalAccount] New AccountBean
[InternalAccount] New AccountBean
[InternalAccount] ejbFind( entity ) InternalAccount
com.uni.account.InternalAcco
untBean@4204
[InternalAccount] SQL:  Select * from Account where ENTITY_ID=3 AND
ACCOUNT_ORDE
R = 0
[InternalAccount] Result = org.jboss.minerva.jdbc.ResultSetInPool@b8a47
[InternalAccount] Balance = 60.0
[InternalAccount] ejbStore() InternalAccount
com.uni.account.InternalAccountBean
@524e3f
[InternalAccount] InternalAccountBean ejbStore() called
[InternalAccount] ID is 3
[InternalAccount] SQL: Update Account set ENTITY_ID = 3, BALANCE = 5.0 where
ENT
ITY_ID = 3
[InternalAccount] SQL: Update Account set ENTITY_ID = 3, BALANCE = 5.0 where
ENT
ITY_ID = 3 1 updated
[Customer] Cart value = 55.0 Balance = 5.0
[InternalAccount] ejbStore() InternalAccount
com.uni.account.InternalAccountBean
@524e3f
[InternalAccount] InternalAccountBean ejbStore() called
[InternalAccount] ID is 3
[InternalAccount] SQL: Update Account set ENTITY_ID = 3, BALANCE = 5.0 where
ENT
ITY_ID = 3
[InternalAccount] SQL: Update Account set ENTITY_ID = 3, BALANCE = 5.0 where
ENT
ITY_ID = 3 1 updated



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to