Skip to content

Commit 36d7ee9

Browse files
committed
Add docs for @view
1 parent 26eaef5 commit 36d7ee9

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

docs/mapping/extensions/view.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,57 @@ <h1 id="breadcrumb">
189189

190190

191191
<h2>View</h2>
192+
<p>
193+
We use <code>@View</code> to have an entity map to a database view.
194+
</p>
192195

196+
<pre type="java">
197+
@Entity
198+
@View(name = "order_vw", dependentTables = {"o_order", "o_order_detail"})
199+
public class MyOrderView {
200+
// fields, accessors etc
201+
}
202+
</pre>
203+
<p>
204+
Note that we do not need to map a <code>@Id</code> property (actually we don't
205+
need to map one for a normal entity either).
206+
</p>
207+
208+
<h2>Dependent Tables</h2>
209+
<p>
210+
If we enable L2 caching on the entity that is based on a view then we should
211+
specify via <code>dependentTables</code> the underlying tables that the view
212+
uses. When data for these tables is modified that will automatically invalidate
213+
the L2 cache for that view.
214+
</p>
215+
216+
<h2>Extra DDL to define the view</h2>
217+
<p>
218+
For ebean to execute DDL to create the database view we need to additional have a
219+
<code>extra-ddl.xml</code>. Refer to <a href="/docs/extra-ddl/">docs / extra-ddl</a>
220+
for more details.
221+
</p>
222+
223+
<pre type="xml">
224+
225+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
226+
<extra-ddl xmlns="http://ebean-orm.github.io/xml/ns/extraddl">
227+
228+
<ddl-script name="order views" platforms="h2" drop="true">
229+
drop view order_agg_vw if exists;
230+
</ddl-script>
231+
232+
<ddl-script name="order views" platforms="postgres,oracle">
233+
create or replace view order_agg_vw as
234+
select d.order_id, sum(d.order_qty * d.unit_price) as order_total,
235+
sum(d.ship_qty * d.unit_price) as ship_total
236+
from o_order_detail d
237+
group by d.order_id
238+
</ddl-script>
239+
240+
</ddl-script>
241+
</extra-ddl>
242+
</pre>
193243

194244

195245

0 commit comments

Comments
 (0)