Tuesday, September 29, 2015

DbAdapter - RowSet Column Type Mismatch Error

Problem: 
Invoking an SQL Server stored procedure with the Db Adapter would return the following error:

JCA Binding execute of Reference operation 'dbGetPromotions' failed due to: RowSet Column Type Mismatch Error. The SQL type in the XSD (INT) does not match the SQL type in the RowSet (int identity) for column ReservationID of parameter RowSet0.

This would happen when the DB Adapter would try to return the Output Parameters for the dbGetPromotions operation.

Solution:
Fix the XSD that was generated during the DB Adapter Wizard.

Originally, the XSD had been generated like this:

  <element name="ReservationID" type="int" db:type="INT" minOccurs="0" nillable="true"/>  

However, apparently the db:type needed for the element ReservationID needed to be int identity, so I changed it as follows:

 <element name="ReservationID" type="int" db:type="INT IDENTITY" minOccurs="0" nillable="true"/>  

Usually the same error will tell you what you need to change the db:type to, so just change it accordingly and you're ready to go!

BPEL - Append multiple elements to a list

Problem: I had a list of XML elements like so:
<Messages> <Message Area="RES" Code="Code1"/> <Message Area="RES" Code="Code2"/> <Message Area="RES" Code="Code3"/> </Message>

This is the XSD:


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://danytests.com/soa/bpel-append" targetNamespace="http://danytests.com/soa/bpel-append" elementFormDefault="qualified"> <xsd:element name="Messages" type="MessagesType"> <xsd:annotation> <xsd:documentation>A sample element</xsd:documentation> </xsd:annotation> </xsd:element> <xsd:complexType name="MessagesType"> <xsd:sequence> <xsd:element name="Message" maxOccurs="unbounded"> <xsd:complexType> <xsd:attribute name="Area" type="xsd:string"/> <xsd:attribute name="Code" type="xsd:string"/> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:schema>
What I needed to do was append more items to the already existing list without affecting the ones that were already in there.

At first what I was doing was adding the new items to add to a BPEL variable ($varMessages) that was also of MessagesType. Then, with another variable ($messageCount), I would assign the count of Messages/Message PLUS 1 to it (so, in this case, it would be 4). In a foreach loop, starting with $messageCount, I would do a simple Copy to Messages/Message[$messageCount] and setting the insertMissingToData flag. This, however, isn't really the right way to go about this.

Solution: Use the BPEL Append action instead of the Copy action.

To accomplish this, I would still have the $varMessages variable assigned with the new items to add, but instead my BPEL assign activity would look like this:


<assign name="appendMessages"> <extensionAssignOperation> <bpelx:append> <bpelx:from>$varMessages/ns1:Message</bpelx:from> <bpelx:to>$outputVariable.payload</bpelx:to> </bpelx:append> </extensionAssignOperation> </assign>

That is, I'd assign the Messages from $varMessages to the final list ($outputVariable) in the Messages complexType.

The results were as expected while looking at it in the audit trail. First I'd assign a Message element to the $outputVariable:



Then I'd add elements to $varMessages:



Finally, after the append action, the output variable's final list would look like this:



Neat!