• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question From Mikalai Zaikin's material

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
Firstly I want to thank Mikalai Zaikin for his superb material.
Can someone please explain me ..
"
An enterprise bean instance can access resource managers in a transaction ONLY in the enterprise bean's methods in which there is a TRANSACTION CONTEXT available. An entity bean with container-managed persistence can access its persistent state in a transaction ONLY in the enterprise bean's methods in which there is a TRANSACTION CONTEXT available.
"
What can TRANSACTION CONTEXT here mean ???
Thanx in Advance
RUF SCJP 1.4
 
Saloon Keeper
Posts: 3947
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Johny.
This not my material, this was taken from EJB spec.
My understanding of this excerpt is :
1. If you do anything with DB from bean's method - you *must* be in transaction context (somebody has to start transaction before you do anything with DB Connection, for example). Because in case method fails to commit, all your changes of DB should be rolled back as well.
2. About state access. If Bean is not in transaction, it's prohibited to call context.getRollbackOnly() or context.setRollbackOnly, because this makes no sense and will throw an exception -> bean will be removed by container. That's why you must be sure that bean' method is running in transaction, if you call any transaction-related method from EJB's context.
.... and that's why "Supports" transaction attribute can be a REAL PAIN, because there is no way to know for sure in which state (Tx or no Tx) method is running....
Cheers!
 
J Johny Rufus
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Mikalai,
So if i am not in a transaction but try to acccess a DB resource...will the code complain in deploy time ???
RUF
 
Mikalai Zaikin
Saloon Keeper
Posts: 3947
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid, it will complain runtime...
 
J Johny Rufus
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Mikalai. I can comprehend.
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic