CINXE.COM
H2 | Ebean ORM
<!doctype html> <html lang="en"> <head> <title>H2 | Ebean ORM</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="shortcut icon" href="/images/favicon.ico"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro|Ubuntu&display=swap"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous"> <link rel="stylesheet" href="/css/reset3.css"> <link rel="stylesheet" href="/css/site3.css"> <link rel="stylesheet" href="/css/pygments3.css"> </head> <body> <div id="main"> <div id="banner"> <header> <nav id="top"> <h1 id="breadcrumb"> <a class="nav-logo" href="/"><img src="/images/logo-200.png" height="35"></a> <a href="/docs">Documentation</a><span class="sep"> / </span><a href="/docs/database">Database platforms</a><span class="sep"> / </span><span class="last">H2</span> </h1> <ul> <li><a onclick="toggleTheme();" title="switch dark light theme"><i class="fas fa-adjust"></i></a></li> </ul> </nav> </header> </div> <div class="grid grid-docs"> <aside> <nav class="side"> <ul> <li class="nav0 "> <a href="/docs/getting-started">Getting started</a> </li> <li class="nav0 "> <a href="/docs/intro">Introduction</a> </li> <li class="nav0 active"> <a class="active" href="/docs">Documentation</a> <ul> <li class="nav1 "> <a href="/docs/best-practice">Best practice</a> </li> <li class="nav1 "> <a href="/docs/query">Query</a> </li> <li class="nav1 "> <a href="/docs/persist">Persist</a> </li> <li class="nav1 "> <a href="/docs/transactions">Transactions</a> </li> <li class="nav1 "> <a href="/docs/mapping">Mapping</a> </li> <li class="nav1 "> <a href="/docs/ddl-generation">DDL & Migrations</a> </li> <li class="nav1 "> <a href="/docs/logging">Logging</a> </li> <li class="nav1 "> <a href="/docs/testing">Testing</a> </li> <li class="nav1 "> <a href="/docs/read-replicas">Read Replicas</a> </li> <li class="nav1 active"> <a class="active" href="/docs/database">Database platforms</a> <ul class="nav"> <li > <a href="/docs/database/postgres">Postgres</a> </li> <li class="active"> <a class="active" href="/docs/database/h2">H2</a> </li> <li > <a href="/docs/database/mysql">MySql</a> </li> <li > <a href="/docs/database/mariadb">MariaDB</a> </li> <li > <a href="/docs/database/sqlserver">SQL Server</a> </li> <li > <a href="/docs/database/oracle">Oracle</a> </li> <li > <a href="/docs/database/db2">DB2</a> </li> <li > <a href="/docs/database/hana">SAP Hana</a> </li> <li > <a href="/docs/database/sqlite">Sqlite</a> </li> <li > <a href="/docs/database/clickhouse">ClickHouse</a> </li> <li > <a href="/docs/database/cockroach">Cockroach</a> </li> <li > <a href="/docs/database/yugabyte">YugabyteDB</a> </li> <li > <a href="/docs/database/nuodb">NuoDB</a> </li> <li > <a href="/docs/database/elasticsearch">ElasticSearch</a> </li> <li > <a href="/docs/database/redis">Redis</a> </li> </ul> </li> <li class="nav1 "> <a href="/docs/multi-database">Multiple databases</a> </li> <li class="nav1 "> <a href="/docs/kotlin">Kotlin</a> </li> <li><a href="/docs/tuning">Tuning</a></li> <li class="nav1 "> <a href="/docs/features">Features</a> </li> </ul> </li> <li class="nav0 "> <a href="/support">Getting help</a> </li> <li class="nav0 "> <a target="_blank" href="/apidoc/13">API Javadoc</a> </li> <li class="nav0 "> <a href="/videos">Videos</a> </li> <li class="nav0 "> <a href="/docs/upgrading">Upgrading</a> </li> <li class="nav0 "> <a href="/releases">Releases</a> </li> </ul> </nav> </aside> <article> <form action="https://www.google.com/search" method="get" class="inline-form"> <input type="hidden" name="as_sitesearch" value="ebean.io"> <div id="page-search"> <div class="input-group"> <input class="frm" name="q" id="searchinput" type="text" placeholder="Search... (press 's' to focus)" data-placeholder-focus="Search... (use '↑', '↓' and '⏎' to select results)" data-placeholder-blur="Search... (press 's' to focus)" autocomplete="off"> <div class="input-group-btn"> <button class="frm" type="submit"><i class="fas fa-search"></i></button> </div> </div> <div id="page-search-results" style="display: none;"> <ul id="search-results-container" class="search-results"><li class=" active"><a href="/docs" title="Docs"><span style="color:#777;">Docs</span> Documentation </a></li><li class=""><small style="color:#999;">And 101 more...</small></li></ul> </div> </div> </form> <h2>H2</h2> <h3>Testing</h3> <p> To test using H2 set the <em>platform</em> to <code>h2</code> in <code>src/test/resources/application-test.yaml</code> </p> <p> Refer to <a href="/docs/testing">docs / testing</a> if application-test.yaml doesn't exist yet. </p> <div class="syntax yml"><div class="highlight"><pre><span></span><span class="nt">ebean</span><span class="p">:</span> <span class="nt">test</span><span class="p">:</span> <span class="nt">platform</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">h2</span> <span class="c1"># h2, postgres, mysql, oracle, sqlserver</span> <span class="nt">ddlMode</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">dropCreate</span> <span class="c1"># none | dropCreate | migrations</span> <span class="nt">dbName</span><span class="p">:</span> <span class="l l-Scalar l-Scalar-Plain">test</span> </pre></div> </div> <p> The above will use the following defaults: </p> <table class="compact w100"> <tr><th>url:</th><td>jdbc:h2:mem:{databaseName}</td></tr> <tr><th>driver:</th><td>org.h2.Driver</td></tr> </table> <h2 id="ebean-h2">ebean-h2 dependency</h2> <p> We can use the <code>io.ebean:ebean-h2</code> dependency rather than <code>io.ebean:ebean</code> if we want to only bring in the H2Database specific platform code. Depending on <code>io.ebean:ebean</code> will bring in all platforms. </p> <h2 id="types">Types</h2> <h5>UUID</h5> <p> UUID is a native H2 type. </p> <h2 id="history">History support</h2> <p> History support for H2 is provided by generating triggers and history table. </p> <nav class="next"> <p class="edit-page"> <a href="https://github.com/ebean-orm/website-source/blob/master/docs/database/nuodb/index.html"><i class="fab fa-github"></i> Edit Page</a> </p> <p class="next"> <a href="/docs/database/postgres" class="btn btn-info">Next: Postgres</a> </p> </nav> </article> </div> </div> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="/js/site3.js"></script> <script src="/js/search3.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-75181644-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-75181644-1'); </script> </body> </html>