【问题标题】:Mule - getting primary key back after insertMule - 插入后取回主键
【发布时间】:2014-06-08 17:54:01
【问题描述】:

从下面的文章中,我了解到 Mule 在插入语句后不会返回自动生成的主键。是否有任何解决方法来获取 PrimaryKey?我不喜欢本文提到的mybatis。

感谢任何帮助!

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

【问题讨论】:

    标签: 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。

    【讨论】:

    • 谢谢戴夫!但在这种情况下,主键是由数据库自动生成的。但是使用此链接中提到的 strategyFactory,我可以取回主键。 mulesoft.org/jira/browse/MULE-6306
    猜你喜欢
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    相关资源
    最近更新 更多