• 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

Issues in db insertion

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??

 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are these inserts to record error details?

 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic