Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping RawSql Result to Object in Java Ebean
    primarykey
    data
    text
    <p>Let's say I have a class <code>Article</code> which is automatically mapped by Java Ebean as a database table.</p> <p>For this table I wanted to retrieve entries via a <code>RawSql</code> 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.</p> <p>The only problem is, that I don't know, how to map the database results to my <code>Article</code> class. I know, that there is a <code>columnMapping(...)</code> method but honestly, I am to lazy to map every single column manually...</p> <p>Isn't there another way to just like <code>myResults.mapToClass(Article.class)</code> to retrieve something like a <code>List&lt;Article&gt;</code>?</p> <p>This is the code I already have:</p> <pre><code>Finder&lt;String, Article&gt; find = new Finder&lt;String, Article&gt;( String.class, Article.class); String sql = "SELECT * FROM article [...]"; RawSql rawSql = RawSqlBuilder.parse(sql).create(); List&lt;Article&gt; returnList = find.setRawSql(rawSql).findList(); </code></pre> <p>Alternatively:</p> <pre><code>Finder&lt;String, Article&gt; find = new Finder&lt;String, Article&gt;( 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&lt;Article&gt; resultList = find.setRawSql(rawSql).findList(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload