0

From the below article, i understand that Mule won't return the auto-generated Primary key after insert statement. Is there any work-around to get the PrimaryKey? I don't prefer going for mybatis as mentioned in this article.

Any help is appreciated!

http://ricston.com/blog/rant-mule-jdbc-transport-introduction-mule-module-mybatis/

Kgan
  • 35
  • 2
  • 12

2 Answers2

2

try using new DB module availabe in 3.5.0-M4 or wait a few weeks for Mule ESB 3.5.0. Here is a usage example of this new feature:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:db="http://www.mulesoft.org/schema/mule/db"
  xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
        http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">

<flow name="insertWithAutoGeneratedKeys">
    <inbound-endpoint address="vm://insertWithAutoGeneratedKeys" exchange-pattern="request-response"/>

    <db:insert config-ref="dbConfig" autoGeneratedKeys="true" autoGeneratedKeysColumnIndexes="1">
        <db:parameterized-query>INSERT INTO PLANET(POSITION, NAME) VALUES (777, 'Mercury')</db:parameterized-query>
    </db:insert>
</flow>

Ale Sequeira
  • 2,039
  • 1
  • 11
  • 19
  • Thanks Ale! I am using Mule 3.3.2. However using the strategyFactory mentioned in this link, i could get back the primary key. https://www.mulesoft.org/jira/browse/MULE-6306 – Kgan Apr 24 '14 at 20:11
0

Alternative: Use UUIDs for primary key and generate the UUID in Mule before the insert.

David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • 1
    Thanks Dave! But in this case, Primary key is auto-generated by DB. However using the strategyFactory mentioned in this link, i could get back the primary key. https://www.mulesoft.org/jira/browse/MULE-6306 – Kgan Apr 24 '14 at 20:08