Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issues in db insertion

 
shweta misra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We are facing a problem in our java application while inserting and updating data into the db.
The code for insertion/updation has been written in core java (jdk1.6).

The steps are as follows :-
1) code is written to insert/update data is 3 tables in the db
2) Soon after step 1, an exception is thrown

a snippet of the code is given below :-

dbentry.finalDBEntriesForSessionRelease(sessionId,"UPDATE", customCdrSession, "error_closed"); //update the db

throw ExceptionType.SERVICE_ERROR.createEx(); //throw exception.

We observed that the java code runs perfectly , the exception is also thrown as expected. The logs show that the db
insertion/updation is done . there are no errors.
But the problem is that the db insertion done in the 3 tables is not visible when we actually go and look into the tables. i.e
we are not able to see the new row that is inserted and the changed rows that are updated in the tables. its like as if nothing
happened. There are no errors also... code works perfectly.

Another observation is that the moment we remove the "throw Exception..." line, we are able to see the db changes in the tables.

Does anyone know why this is happening and how to resolve this ??

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Shweta!

My really, really wild guess is that you have turned autocommit off and there is a rollback somewhere in your exception handling code.

If this is true, the resolution depends on what you're tying to achieve. Rolling back changes when an error occurs is quite common and reasonable approach, actually.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, thre is not enough information here to work upon.

Please read this link and come back to us. isolate the problem

 
shweta misra
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Martin !

our application is deployed in the Weblogic application server and the transactions are container managed and the EJBs are stateless session beans. I found that for container managed transactions, in case of a system exception the transaction is rolled back . this will include db updates also.

as per our business logic we need to update certain db tables before we throw the exception but looks like its not possible.

Can you suggest any workaround ?
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are these inserts to record error details?

 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shweta misra wrote:thanks Martin !

our application is deployed in the Weblogic application server and the transactions are container managed and the EJBs are stateless session beans. I found that for container managed transactions, in case of a system exception the transaction is rolled back . this will include db updates also.

as per our business logic we need to update certain db tables before we throw the exception but looks like its not possible.

Can you suggest any workaround ?


I was wondering why you are throwing an Exception on purpose - and wondering too if that is what Wendy is getting at. But if you have autocommit turned off, you could force the commit before throwing the exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic