# Hibernate used with H2 - In Memory DB needed

**URL:** <https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424>\
**Category:** Miscellaneous\
**Created:** [June 20, 2022, 6:54pm UTC](https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424 "2022-06-20T18:54:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [June 20, 2022, 6:54pm UTC](https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424/1 "2022-06-20T18:54:38Z")

</div>

We are developing new Genealogy solution based on Java and H2 database. Hibernate ORM seems to be a promising as alternative to manual handling of database with ResultSet. However all examples I have seen with H2 and hibernate use “in Memory” H2 database option. Out solution use H2 as ordinary embedded H2 database stored in the filesystem.  
Qestion: Need the H2 database to run in “in Memory” mode when used with Hibernate?

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [June 21, 2022, 6:57am UTC](https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424/2 "2022-06-21T06:57:21Z")

</div>

> [@Nils\_Tolleshaug](#):
>
> Qestion: Need the H2 database to run in “in Memory” mode when used with Hibernate?

No, you don’t have to. That’s unrelated to Hibernate ORM, by the way: this is a configuration option of H2; you’ll simply use a different JDBC URL depending on where you want H2 to store its data.

See in particular the [H2 documentation](http://h2database.com/html/cheatSheet.html):

> [Database URLs](http://h2database.com/html/features.html#database_url)
> 
> **[Embedded](http://h2database.com/html/features.html#connection_modes)**  
> `jdbc:h2:~/test` ‘test’ in the user home directory  
> `jdbc:h2:/data/test` ‘test’ in the directory /data  
> `jdbc:h2:./test` in the current(!) working directory
> 
> **[In-Memory](http://h2database.com/html/features.html#in_memory_databases)**  
> `jdbc:h2:mem:test` multiple connections in one process, database is removed when all connections are closed  
> `jdbc:h2:mem:test;DB_CLOSE_DELAY=-1` multiple connections in one process, database in not removed when all connections are closed ([may create a memory leak](http://h2database.com/html/features.html#in_memory_databases))  
> `jdbc:h2:mem:` unnamed private; one connection
> 
> **[Server Mode](http://h2database.com/html/tutorial.html#using_server)**  
> `jdbc:h2:tcp://localhost/~/test` user home dir  
> `jdbc:h2:tcp://localhost//data/test` or `jdbc:h2:tcp://localhost/D:/data/test` absolute dir  
> [Server start](http://h2database.com/html/tutorial.html#using_server):`java -cp *.jar org.h2.tools.Server`
> 
> **[Settings](http://h2database.com/html/features.html#database_url)**  
> `jdbc:h2:..;MODE=MySQL;DATABASE_TO_LOWER=TRUE` [compatibility (or HSQLDB,…)](http://h2database.com/html/features.html#compatibility)  
> `jdbc:h2:..;TRACE_LEVEL_FILE=3` [log to \*.trace.db](http://h2database.com/html/features.html#trace_options)

---

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [June 21, 2022, 7:21pm UTC](https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424/3 "2022-06-21T19:21:05Z")

</div>

Thanks for the answer. Then I see that Hibernate and H2 also will work in H2 Server mode.  
Nils

---

<div class="post-metadata">

**Author:** ![Nils\_Tolleshaug](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/nils_tolleshaug/32/1937_2.png) [@Nils\_Tolleshaug](https://discourse.hibernate.org/u/Nils_Tolleshaug)\
**Post date:** [June 30, 2022, 4:56pm UTC](https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424/4 "2022-06-30T16:56:08Z")

</div>

Sorry?

New question refused with error message:  
“Sorry, new users can only mention 2 users in a post.”  
Cannot understand the message and understand whats wrong?  
Rgs Nils

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [July 1, 2022, 6:51am UTC](https://discourse.hibernate.org/t/hibernate-used-with-h2-in-memory-db-needed/6424/5 "2022-07-01T06:51:04Z")

</div>

See [Sorry, new users can only mention 2 users in a post](https://discourse.hibernate.org/t/sorry-new-users-can-only-mention-2-users-in-a-post/3933)
