Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

JDBC connection and transactions

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if the spec says anything about this, but if you have a EJB bean method running in a transaction and then open a JDBC connection and make a SQLStatement, is the transaction of the method propagated into the database such that a SQL update statement will rollback if an EJBException occurs.

Any ideas?

Peter
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't think the transaction of the EJB bean is propagated
into the database, since the JDBC methods are non-EJB methods,
and they can't have transaction attributes specified in the
deployment descriptor like CMP beans.

Cheers,

Gian
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if you have a EJB bean method running in a transaction and then open a JDBC connection and make a SQLStatement, is the transaction of the method propagated into the database such that a SQL update statement will rollback if an EJBException occurs.



Yes... but the rollback/commit is guaranteed to work only if the EJB uses javax.sql.DataSource to 'get' the connection and the DataSource is managed by the container in which the bean is running.

If you use plain JDBC in the bean, there is no guarantee.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Keerthi,

Glad that you are still posting on this board.
Thanks for all your helful replies.

Gemini
[ March 14, 2005: Message edited by: Gemini Moses ]
 
Keerthi P
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Keerthi,

Could you please explain further , given the following
example, which uses javax.sql.Datasource to get the
connection as you mentioned:


Here, the first SQL statement after connect, commit, or rollback
implicitly initiates a JDBC transaction. Therefore I still
think the transaction of the calling bean won't be propagated to
the database.

Cheers,

Gian
[ March 15, 2005: Message edited by: Gian Franco Casula ]
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An Enterprise bean should not use commit and tx methods from Connection interface in bean code to interfere in Transactions!!!
Amol.
 
Gian Franco
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

EJB bean-managed transaction (BMT)
offers the ability to use JDBC type
or JTA type transactions. Although
mixing JTA and JDBC transactions
is not recommended.

The above example is valid though

Cheers,

Gian
 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is brilliant. I didn't know I started off a such discussion. BMT is definetly a bad idea.
 
Acetylsalicylic acid is aspirin. This could be handy too:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic