Ibatis:有没有办法在 sqlmap xml 中的 Ibatis 结果映射子选择中添加行处理程序?

发布于 2024-08-14 10:37:11 字数 631 浏览 3 评论 0原文

我有两个 ibatis sql 映射,它们通过子选择链接在一起,如下面的简化示例所示:

<resultMap id="order" class="Order">
  <collection property="orderLines" ofType="OrderLine" resultMap=”orderLine”/>
</resultMap>

我有一个订单对象,其中包含由联接和关联返回的行对象的集合。我希望对返回订单行的嵌套关联返回的每一行执行一些行处理程序功能。

我知道这可以通过在调用 spring sqlmapclienttemplate 查询列表时将 IListRowHandler 传递给 queryWithRowHandler 调用来实现。 OrderLine 对象,但这不允许我在仅对父 sql 映射(本例中为 order)进行调用时在子选择集合上使用行处理程序。

有没有办法以声明方式将 rowhandler 类分配给 ibatis sql 映射中的特定结果映射或 select 语句?因为这是我认为应该存在的功能。或者,我愿意接受有关修改子选择返回的行对象的每个实例的建议,因为它们被返回,而不是询问完全构建的订单对象并在事后操作它们。

I have a two ibatis sql maps that are linked together via a sub select like the simplified example below:

<resultMap id="order" class="Order">
  <collection property="orderLines" ofType="OrderLine" resultMap=”orderLine”/>
</resultMap>

I have an order object that contains a collection of line objects that are returned by a join and an association. I wish to perform some row handler functionality on every line that is returned by the nested association that returns the order lines.

I know that this can be achieved by passing in a IListRowHandler to the queryWithRowHandler call when calling the spring sqlmapclienttemplate for a query for just a list of OrderLine objects, but this does not allow me to use a rowhandler on the subselect collection when making a call only on the parent sql map, order in this example.

Is there any way to declaritively assign a rowhandler class to a specific resultmap or select statement within an ibatis sql map? As this is the kind of functionality i feel should be there. Or alternatively i am open to suggestions on modifying each instance of the row objects returned by the sub select as they are returned rather than interrogating the fully built order object and manipulating them after the fact.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老子叫无熙 2024-08-21 10:37:12

我浏览了 iBatis 文档,寻找适合的内容,但没有成功。

所以我实现了以下解决方案:

在作为查询执行结果通过 ibatis 填充的 Order.setOrderLines(collection orderLines) 方法上,我实现了一个处理程序方法来操作每个 < code>orderLines 位于即将在 Order 上设置的集合中。

这并没有实现每个嵌套对象在实例化时和添加到集合之前的拦截,但它完成了这项工作,并以与查询无关的方式尽早执行它,以便在任何时候激活它。查询使用 Order resultMap 作为返回值。

如果有人提出一个解决方案,我很高兴将执行我首先想要的任务的任何声明式解决方案标记为答案!

I have had a look through the iBatis documentation for something that will suit without success.

So i have implemented the following solution:

On the Order.setOrderLines(collection orderLines) method that is populated via ibatis as a result of the query execution, I have implemented a handler method that manipulates each of the orderLines within the collection that is about to be set on the Order.

This doesn't do achieve the interception of each nested object as it is instantiated and before it is added to the collection, but it does the job, and performs it early enough and in a query agnostic way so that it is activated any time a query utilises the Order resultMap as a return value.

I'm happy to mark any declarative type solution that perform the task as I first wanted as the answer, if someone comes forward with one!

无畏 2024-08-21 10:37:11

听起来您正在使用 N+1 选择方法,这可能会导致即使对于简单的查询也会执行大量选择,而这通常是不可取的。请参阅 iBatis 用户指南中的“关联的嵌套结果”部分,该部分提供了该问题的替代解决方案,基本上您可以在主查询中进行联接,然后在 resultMap 级别使用聚合来映射到您的对象模型,因此结果您可以简单地在主查询上使用行处理程序。

It sounds like you are using N+1 select approach, which could result in numerous selects executed even for a simple query and that is usually not desirable. See "Nested Results for Association" section in iBatis User Guide that provides an alternative solution to the issue, basically you can do a join in your main query and then use aggregation at the resultMap level to map to your object model, so in result you can simply use a row handler on the main query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文