using ebean (via play framework 2.1.1), have build home made sql query, i'd return directly list<mymodel>
, instead of list<sqlrow>
have query database each id result have list<mymodel>
.
is possible cast directly sqlquery/sqlrow model ?
actually, :
sqlquery query = ebean.createsqlquery("select id mymodel ..."); list<sqlrow> rows = query.findlist(); // not directly possible. list<mymodel> results = new arraylist<mymodel>(); (sqlrow row : rows) { results.add(mymodel.find.ideq(row.getlong("id))); }
ideally, :
sqlquery query = ebean.createsqlquery("select id mymodel ..."); list<mymodel> results = (list<mymodel>) query.findlist(); // not directly possible.
not efficient :s
thanks help!
try this:
rawsql rawsql = rawsqlbuilder.parse("select id, value, ... mymodel ...") .columnmapping("id", "id") .columnmapping("value", "value") //... .create(); query<mymodel> query = ebean.find(mymodel.class); query.setrawsql(rawsql); list<mymodel> result = query.findlist();
or using finder:
finder<long, mymodel> finder = new finder<long, mymodel>(long.class, mymodel.class); list<mymodel> result = finder.where() .eq("name", "barack obama") //... .findlist();
Comments
Post a Comment