最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Force JOIN query for Spring Data JDBC - Stack Overflow

programmeradmin0浏览0评论

Is there any way or some kind of extension which will generate JOIN query for default Spring Data JDBC repositories?

For example:

public class Root {

    private @Id Long id;
    private String name;

    @MappedCollection(idColumn = "root_id")
    private Set<Child> list = new HashSet<>();
}

public class Child {

    private @Id Long id;
    private Long rootId;
    private String element;
}

This will generate two separate queries for findAllById() method:

SELECT * FROM Root WHERE id = :id
SELECT * FROM Child WHERE rootId = :id

But I would like to have simple left join, something like:

SELECT r.id, r.name, c.id, c.rootId, c.element FROM Root AS r
LEFT JOIN Child AS c ON r.id = c.root_id
WHERE r.id = :id

Is that possible somehow?

发布评论

评论列表(0)

  1. 暂无评论