microorm
microorm copied to clipboard
best approach to use microorm with joins
I am wondering how microorm can be implemented to deal with a cursor from a join result having same column names.
After joining two columns my cursor looks like:
0 = "id"
1 = "name"
2 = "category_id"
3 = "id"
4 = "name"
5 = "price"
Of course microorm cannot handle something like this automatically. My approach was to give the column names an alias.
0 = "Foo_id"
1 = "Foo_name"
2 = "Foo_category_id"
3 = "Bar_id"
4 = "Bar_name"
5 = "Bar_price"
But now i need to rename the @Column annotation, so it doesn't fit to my database structure anymore.
Any ideas?
I'd go with columns aliases + separate POJO for joined results. So I'd have three annotated POJOs:
class Foo {
@Column("id")
long id;
@Column("name")
String name;
}
class Bar {
@Column("id")
long id;
@Column("name")
String name;
}
class FooBar {
@Column("foo_id")
long fooId;
@Column("foo_name")
String fooName;
@Column("bar_id")
long barId;
@Column("bar_name")
String barName;
}
Quite a bit of boilerplate, but I don't see a good generic solution at the moment.