• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When the JDBC transaction begin?

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

When the jdbc transaction is begin?
If i have some layer each of them is stateless bean with transaction required - true.
So, is the jdbc transaction begin even before i do any transaction activity?


Thank you
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your EJB method is marked as requiring a transaction, one is started before the method is called. A google search should yield several tutorials on EJB transaction handling. Here's one: http://java.sys-con.com/node/36596
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am familiar with ttransaction in j2ee,
but,....


suppose that you have facade with method serviceYYY that marked as transaction - required.

In your applicatiioon server you have severla datasources, so when you call to serviceYYY accordimg to what you say ther server in the begining of method serviceYYY will pop connection from each pool and start a jdbc transaction for each connection source, even if no database activity is required.
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ther server in the begining of method serviceYYY will pop connection from each pool


The time at which the app gets a connection from the app server's connection pool has nothing to do with the transaction settings of the method. Instead, it is entirely dependent on what persistence mechanism is used - JPA/Hibernate will behave differently (in terms of obtaining a connection from the connection pool) than if you are doing your own persistence handling, or if you are using some other persistence framework.

Transaction state in Java EE does not necessarily require a transaction state in the database. Most databases do not require that you specifically call a "start transaction" function. Instead, the database enters transaction state on the first update when autocommit is not set. Until such an update is done, there might not be any interaction with the database.

even if no database activity is required.


Since serviceYYY is marked as requiring a transaction, one will be created even if no database update is every done by the code.
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for not beeing clear.
I will try to be clear now.
Thank you for your answer.

I am not questioning about when the j2EE transaction begin.

I will be more specific.
Jboss + JPA (hibernate).

When the trnsaction begin in the DB?
is it when the entitymanager injected in the first time during the j2ee transaction scope?
is it after the first query or after the first update?


Thank you
 
Peter Johnson
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[quote[When the trnsaction begin in the DB?
That depends on the database - you'll have to read the database docs to find out. Usually, it is when the first update takes place. Remember that in general transactions are a way to group all changes to a database into a logical group so that they can either be applied as a whole, or discarded.

I have not monitored the database interactions that take place while using Hibernate, so I cannot state exactly when the first update is sent to the database.
 
reply
    Bookmark Topic Watch Topic
  • New Topic