Showing posts with label DBAdapter. Show all posts
Showing posts with label DBAdapter. Show all posts

Monday, November 12, 2012

DBAdapter workaround for inserting non-ISO date formats


In SOA there will be many projects which will migrate from using db triggers/procedures to transfer data between different databases/systems to using fusion middleware.
One of the main issues that has DB inserts is due to the legacy way in which Date would have been inserted .It may not be following any ISO standards.
DB adapters would be conforming to iso 8601 xs:dateTime format

From Console error snapshot
               *
ERROR at line 1:
ORA-01830: date format picture ends before converting entire input string

<faultType>0</faultType>
<bindingFault>
<part  name="detail">
<detail> Exception Description: The object [27-Jun-2012 7:12:25 ], of class [class java.lang.String], could not be converted to [class java.sql.Timestamp]. Internal Exception: BINDING.JCA-11636 Could Not Convert Timestamp Exception. Unable to convert a string value in the xml to a java.sql.Timestamp. Even though databases accept strings representing timestamps in a variety of formats, the adapter only accepts strings representing them in xml ISO dateTime format. The input value must be in iso 8601 xs:dateTime format, i.e. YYYY-MM-DDTHH:MM:SS.sss-07:00 </detail>

Solution
1.    Use a custom SQL for insert instead of using Out of the box Insert query.
Since the format that we want in tables are non-ISO format, use TO_DATE function in the custom query with the format - TO_DATE(#DATE_VALUE,'DD-Mon-YYYY HH24:MI:SS'),.


Eg: INSERT INTO LOAD (shipment_id, transaction_id, action_code, create_timestamp, update_timestamp, e1_release_start_date,  e1_release_end_date)    VALUES (#E0Z58SHPID, #E0Z58TRNID, #E0ACTI, TO_DATE(#SSTM,'DD-Mon-YYYY HH24:MI:SS'), TO_DATE(#SSUTM,'DD-Mon-YYYY HH24:MI:SS'),)


2.    Check your XSD element types. Change datetime to string.

      <xs:element name="SSUTM" type="xs:datetime" nillable="true"/>
         <xs:element name="SSUID" type="xs:datetime" nillable="true"/>
to
      <xs:element name="SSUTM" type="xs:string" nillable="true"/>
         <xs:element name="SSUID" type="xs:string" nillable="true"/>

That’s it, now you should be able to insert the records propeprly into legacy databases in date formats not supported by the DB adapter.

Thursday, November 8, 2012

Transaction rollback in SOA 11g - Error not getting propogated through Toplink



I encountered one error scenario in PS5. Had developed a process in PS5. The process shows all interaction as successful but finally the transaction was getting rolled back. The em console shows the process instance as errored out but no errors were shown.
The process involves multiple DB interactions was triggered by polling a table.




BPEL process instance "1040126" completed
The transaction was rolled back. The work performed for bpel instance "1040126" was rolled back, but the audit trail has been saved for this instance.If this is a sync request, please resubmit the request from the client. If it is an async request, please recover from the recovery console by resubmitting the invoke message.The transaction was rolled back. The work performed for bpel instance "1040126" was rolled back, but the audit trail has been saved for this instance.If this is a sync request, please resubmit the request from the client. If it is an async request, please recover from the recovery console by resubmitting the invoke message.


As always the only option was to go behind the scenes ,enable  logging to TRACE-FINEST for oracle.soa.adapter and monitor the logs.

The issue was due to a CONSTRAINT in the table which was being violated by the polling process which was inserting a value not supported by constraint for that column.

Error from Log File

012-11-08T02:43:31.005-06:00] [fmwDirect-directi02] [ERROR] [] [oracle.soa.adapter] [tid: Workmanager: , Version: 0, Scheduled=false, Started=false, Wait time: 0 ms\n] [userId: <anonymous>] [ecid: 8a5d5fb1e9381abe:13601ac5:13adc7cdc79:-8000-000000000001747c,0] [APP: soa-infra] Database Adapter TestProcess <oracle.tip.adapter.db.InboundWork handleException> Encountered a fatal exception while polling.  Will continue polling but with minimal logging.  Please investigate the fault and manually stop polling from the console if in development and this appears to be a modeling mistake.  BINDING.JCA-11624[[
DBActivationSpec Polling Exception.
Query name: [triggerTransactionSelect], Descriptor name: [triggerTransaction.Transaction]. Polling the database for events failed on this iteration.
Caused by java.sql.BatchUpdateException: ORA-02290: check constraint (STATUS) violated
.
  This exception is considered not retriable, likely due to a modelling mistake.  To classify it as retriable instead add property nonRetriableErrorCodes with value "-2290" to your deployment descriptor (i.e. weblogic-ra.xml).  This polling process will shut down, unless the fault is related to processing a particular row, in which case polling will continue but the row will be rejected (faulted).

               at oracle.tip.adapter.db.exceptions.DBResourceException.createNonRetriableException(DBResourceException.java:690)


Inference
      The DB adapter will throw an error while interacting with the DB layer. There will be some constraint errors which may not be propagated through the Toplink layer, there by not showing up in the console. But logs will not hide them,and will help you to debug the issue.


Friday, October 19, 2012

Issue with DBAdapter Update due to char datatype & shouldTrimStrings property


Recently I looked into a technical issue with DB adapter where the update was not working even though it was not throwing any error. Everything seems to be working fine but the field is never updated.

All the settings looked fine but the update was not happening. So we checked the table which revealed that the all the string fields were of char type. It didn’t seem to value much as my understanding was that char will work similar to varchar. I was puzzled to see the Note from Oracle @Oracle DBAdapter documentation ,but it was true.

It reads as :: Oracle recommends that you use varchar instead of char for primary key columns, otherwise you must set the weblogic-ra.xml property shouldTrimStrings to false. The truncation of trailing spaces could cause the primary key to be read incorrectly, making it impossible to update read rows as processed.

Issue :: The Primary Key fields in Database were of char type and data contains trailing spaces. Since by default shouldTrimStrings property is set to true, weblogic will trim these spaces, there by it will not be able to fetch the correct rows from DB. So update fails as it will not be able to fetch the row properly.
Solution::
Set the shouldTrimStrings property to false in weblogic DBAdapter Outbound Connection Properties
By default the property shouldTrimStrings is not visible in Outbound Connection Properties, so we will not able to change it.
So to modify the value a new entry needs to added to the DBAdapter config  properties. This is one time configuration task that needs to done by updating the ra.xml from filesystem.
Steps
1.    Take a backup of DBAdapter.rar
2.     Extract the entire content.(use unzip tools)
3.     Edit the META-INF/ra.xml.
Add a property in ra.xml file
           <config-property>
               <config-property-name>shouldTrimStrings</config-property-name>
               <config-property-type>java.lang.Boolean</config-property-type>
               <config-property-value>false</config-property-value>
            </config-property>
   
4.    Re-Create the DbAdapter  rar file.
>>>>jar.exe -cvf DbAdapter.rar -C DbAdapter/ .
added manifest
adding: DBAdapter.jar(in = 551405) (out= 519781)(deflated 5%)
ignoring entry META-INF/
ignoring entry META-INF/MANIFEST.MF
adding: META-INF/ra.xml(in = 13473) (out= 2866)(deflated 78%)
adding: META-INF/weblogic-ra.xml(in = 6713) (out= 1775)(deflated 73%)
adding: toplink-grid.jar(in = 102529) (out= 91349)(deflated 10%)
5.    Update the DBAdapter from Deployments
From Console the property should be available for all the database adapter connection under Outbound Connection Properties.

Thanks to Thani, Lee, Sampath for helping with this issue.