Let's say I have a class Article
which is automatically mapped by Java Ebean as a database table.
For this table I wanted to retrieve entries via a RawSql
query, because I find SQL more simple when it gets to complex queries with many joins and such. By far I have managed to give my SQL statement to the Parser. The query is correct, I already checked that.
The only problem is, that I don't know, how to map the database results to my Article
class. I know, that there is a columnMapping(...)
method but honestly, I am to lazy to map every single column manually...
Isn't there another way to just like myResults.mapToClass(Article.class)
to retrieve something like a List<Article>
?
This is the code I already have:
Finder<String, Article> find = new Finder<String, Article>(
String.class, Article.class);
String sql = "SELECT * FROM article [...]";
RawSql rawSql = RawSqlBuilder.parse(sql).create();
List<Article> returnList = find.setRawSql(rawSql).findList();
Alternatively:
Finder<String, Article> find = new Finder<String, Article>(
String.class, Article.class);
String sql = "SELECT id, title, sub_title FROM article [...]";
RawSql rawSql = RawSqlBuilder.parse(sql)
.columnMapping("id", "id")
.columnMapping("title", "title")
.columnMapping("sub_title", "subTitle")
.create();
List<Article> resultList = find.setRawSql(rawSql).findList();