Table names or aliases as prefix to resolve columns of joined tables
#2,292 opened on 2023/03/13
Repository metrics
- Stars
- (1,745 個のスター)
- PR merge metrics
- (平均マージ 1d 10h) (30d で 6 merged PRs)
説明
Hello!
I wonder if it is possible, using JDBI, to use table names as prefixes for column disambiguation.
For example: I have two Java classes:
class Inner {
String id;
String name;
}
class Outer {
String id;
String value;
@Nested
Inner inner;
}
In my DB, I have two tables:
CREATE TABLE inner(id VARCHAR, name VARCHAR);
CREATE TABLE outer(id VARCHAR, value VARCHAR, inner_id VARCHAR);
I have an OuterDao class that does a simple SELECT operation:
@SqlQuery("SELECT * FROM outer LEFT JOIN inner ON (outer.inner_id = inner.id) LIMIT 1;")
@RegisterConstructorMapper(value = Optional.class)
Optional<Outer> selectOne();
This does not work as there is a matching column name id between the two tables. One solution proposed by JDBI is to set a prefix for the nested entity and then alias all the columns from the nested entity.
Is there a way to use the table names or even table aliases as prefix? This would avoid the 'verbosity' of listing all columns from the inner table and write a smaller query.
For example in the Outer class we could have
@Nested("inner")
Inner inner;
or
@Nested("inner.")
Inner inner
Thanks for the support!