【问题标题】:Mule - getting primary key back after insertMule - 插入后取回主键
【发布时间】:2014-06-08 17:54:01
【问题描述】:
【问题讨论】:
标签:
jdbc
primary-key
mule
auto-generate
【解决方案1】:
尝试在 3.5.0-M4 中使用新的 DB 模块,或者等待几周的 Mule ESB 3.5.0。 Here 是这个新功能的一个使用示例:
<?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>
【解决方案2】:
替代方案:使用 UUID 作为主键,并在插入之前在 Mule 中生成 UUID。