microorm icon indicating copy to clipboard operation
microorm copied to clipboard

best approach to use microorm with joins

Open q0re opened this issue 9 years ago • 1 comments

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?

q0re avatar Jul 08 '16 09:07 q0re

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.

chalup avatar Jul 12 '16 16:07 chalup