This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Transactions... why and how?

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know what trasactions are for DB. But I am having hard time to understand what they do in EJB. So my multiple questions:
1) I have DB (like MySQL) configured for use on some App server. I put my beans (entity beans) and run various methods on my entity beans. Will the container use my DB server transactions .. mhm automatically?
2) The same question but beans are with BMT. I will have to implement those transaction starting calls communicating with my DB driver?
3) I have my entity beans and I want them on some persistant store that is not DB (files!). Can I use entity CMP CMT CMR ? I guess I will have to implement something for my "files" so that container accept it as transactional permanent store?
4) If I have my bean set his data member (which is not virtual field!) to some value in transactional call (like a = 4 .. If I rollback transaction will container automatically restore my data member (which is not field!) to his previous state? I guess not... I have to implement that SyncronizedSession or use EjbLoad.. Right?

If you have answer to any of these please tell me! I love you all.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The container will use the capabilities of the database to make the commit or rollback in both CMT and BMT. The database must support transactions for it to work.
Best Regards
/Magnus
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure about BMT?
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vladas,
1) Yes, but based on the transaction attributes you put in the DD and as far as your DB is supported by your specific EJB container.
2) Entity beans do not support BMT !
3) It's vendor specific (as the DB support)
4) You're right, you'll have to use ejbLoad to restore them. Don't forget that SyncronizedSession is reserved to SESSION beans (stateful).
Best,
Phil.
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi vlada, magnus and phill,
Let me very with you guys my understanding about transaction in EJB and DB. Does a database have to support trasaction in order to make transaction in EJB to work? in another words, is it correct that transaction in EJB always works, does not care whether the database support trasaction or not and it has nothing to do with database transaction support feature? sorry if i could make myself clear.
also vladas, could you please elaborate your last question? you have raised very interesting points here.
namaste
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Philippe,
Entity beans do not, but session beans do support BMT. So in BMT case we have to implement those transaction calls ourselves? Hey, that means we just found another use for BMT! That is if container can't work with my DB or whatever "persistent store", I can write BMT beans (uh oh, ok session only) and do it myself. Wait.. no entity beans ... that is no good.
By the way I forgot. Do stateless beans support transactions at all ?
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Namaste,
As I understood from Philippe answer CMT will restore bean state in the database (if it is CMP). Any other non-managed by container field ain't gonna be restored. We have to do it in ejbLoad (entity beans) or after... (stateless session beans).
I wonder how CMT works with BMP (bean managed persistance) entity beans???
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vladas,

Entity beans do not, but session beans do support BMT. So in BMT case we have to implement those transaction calls ourselves? Hey, that means we just found another use for BMT! That is if container can't work with my DB or whatever "persistent store", I can write BMT beans (uh oh, ok session only) and do it myself.


Yes, AFAIK BMT sessions may call CMT entity business and home business methods. And as far as the trans attributes set for the entity bean methods are "Required" or "Mandatory", the called methods of the entity bean will execute within your BMT context.
Should be confirmed by Kathy or Valentin though, because I may be wrong .
Best,
Phil.
 
Bartender
Posts: 3958
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vladas Razas:

By the way I forgot. Do stateless beans support transactions at all ?


yep, they support both CMT (declarative in DD) and BMT. One of the difference stateLESS from stateFUL though is that for stateLESS bean every method should finish transaction before method finishes, while for stateFUL this is not a mandatory and one transaction can be spreaded over several methods calls which come from client. (But this is a bad idea, since bean has to be kept in memory while in transaction, so if you forgot to call method with commit() or rollback(), then you just spent memory and EJB container is not happy of this).
Cheers!!!
 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,

Originally posted by Mikalai Zaikin:

yep, they support both CMT (declarative in DD) and BMT. One of the difference stateLESS from stateFUL though is that for stateLESS bean every method should finish transaction before method finishes, while for stateFUL this is not a mandatory and one transaction can be spreaded over several methods calls which come from client. (But this is a bad idea, since bean has to be kept in memory while in transaction, so if you forgot to call method with commit() or rollback(), then you just spent memory and EJB container is not happy of this).
Cheers!!!


Is forgetting commit() or rollback() not a problem? What is the point of even starting a trasaction If that transaction is not committed or rollback?the work associated with that trasaction is not completed, right?
namaste
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic