1

I used to run my Java code with Hibernate to mysql.

Some logical changes led me to decide that I don't need to save the data in the database, but in java class that will handle it as a database (The data is delete in every startup of the application).

How can I do in Hibernate? is there a way to create an in memory database?

4 Answers 4

3

Consider H2 (recommended) or HSQLDB. You can certainly use Hibernate with them. In fact, HSQLDB was the database used by default in Hibernate for their test suite (I think they just changed to H2).

Sign up to request clarification or add additional context in comments.

Comments

2

Take a look at Apache Derby.

Comments

1

You could also use SqlLite, which is an in-memory database. I'm just about to start using it with NHibernate for the same purpose in unit tests.

Comments

0

You just need to:

  • add the driver for the database you want to use and change the hibernate settings for this driver,
  • change the setting hibernate database dialect,
  • change the jdbc connection String
  • (add the jars for the database)

For example for Hypersonic H2 Database:

  • driverClassName = org.h2.Driver
  • dialect = org.hibernate.dialect.H2Dialect
  • connection string = jdbc:h2:mem:test

2 Comments

The access to h2 performance wise is the same as accessing mysql?
I think this depends highly on your data and usecases. -- I use H2 to run my "unit"-tests, and this is faster than MySQL, but indeed this is a very special use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.