Skip to content

Exception: java.sql.SQLIntegrityConstraintViolationException: Column 'created_time' in order clause is ambiguous #268

Closed
@ghost

Description

code:

        SelectStatementProvider ssp = select(category.id,
                category.name,
                item.id.as("itemId"),
                item.itemName,
                itemImg.url.as("imgUrl"))
                .from(category, "a")
                .leftJoin(item, "b")
                .on(category.id, equalTo(item.catId))
                .leftJoin(itemImg, "c")
                .on(item.id, equalTo(itemImg.itemId))
                .where(category.id, isEqualTo(id))
                .orderBy(item.createdTime)
                .build()
                .render(RenderingStrategies.MYBATIS3);

generated sql:

select
    a.id, a.name, b.id as itemId, b.item_name, c.url as imgUrl
from
    category a
left join
    item b
on
    a.id = b.cat_id
left join
    item_img c
on
    b.id = c.item_id
where
    a.id = ?
order by
    created_time

The tables "item" and "item_img" have the same column "created_time", and the "order by" clause doesn't add table alias as the column's prefix, so it crashed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions