Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with CMT Stateless Session Bean setRollbackOnly() not working

All,

I've been reading a ton of posts on this subject and have not found an
answer.

I am using WebLogic 8.1.  I have an application with a bean whose
deployment descriptor indicates that transactions are to be
container-managed.  The deployment descriptor also indicates which
methods use REQUIRED for their <trans-attribute>.  I then have a small
piece of code that modifies a database, purposely throws an exception,
catches the exception, and then calls setRollbackOnly().
Unfortunately, even though setRollbackOnly is being called, the changes
to the database are being committed.  I don't know why.

Here's an example of the code:

public String methodUsingRequiredAttribute() {

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection oConn = DriverManager.getConnection("oracleThisDriver",
"aUser", "aPassword");
// .. create a statement .. update a table in the database
try {
throw new Exception("testing rollback");
}
catch(Exception e) {
getContext().setRollbackOnly();
System.out.println("setRollbackOnly didn't throw error");
}
}

When I run this code, it prints out that setRollbackOnly didn't throw
an error - but the database remains changed.  Any thoughts on what I'm
doing wrong?  I know that ideally I'd get a connection from a
datasource - and I'm not doing that here - but I don't see how that
changes things.

Is it possible there's something wrong with the database driver that
I'm using (the oracle thin driver)?  Or my version of WebLogic 8.1?

I'm at a loss...

Any light you can shed would be appreciated.

-john


Report this thread to moderator Post Follow-up to this message
Old Post
theRat
04-13-05 01:59 AM


Re: Problem with CMT Stateless Session Bean setRollbackOnly() not working
I want to make sure I understand your answer.  Are you saying that the
way I currently obtain my connection is "bypassing" the container so
that the call to setRollbackOnly isn't working?  If that's the case,
then I'm happy to change how I obtain my connection.

How do I do that?  What is the correct way to obtain a connection so
that the container-managed transaction model isn't broken?

-john


Report this thread to moderator Post Follow-up to this message
Old Post
theRat
04-13-05 01:59 AM


Re: Problem with CMT Stateless Session Bean setRollbackOnly() not working
The WL doc indicates that calling setRollbackOnly should cause a CMP transac
tion to rollback, but experience told me that you need to throw the exceptio
n to trigger the rollback. (see below).

- Daniel

try {
  throw new Exception("testing rollback");
}
catch(Exception e) {
  getContext().setRollbackOnly();
  System.out.println("setRollbackOnly didn't throw error");
  throw e;  // needed to trigger the rollback.
}

Report this thread to moderator Post Follow-up to this message
Old Post
kw888
04-21-05 08:43 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Beans archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:08 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.