开发者

How to use MySql Memory Storage Engine in Hibernate?

开发者 https://www.devze.com 2023-04-04 23:36 出处:网络
Is there any way to tell Hibernate use MySql Memory Storage Engine? Thanks. Edit: I found Memory Storage Engine does not support all fea开发者_运维问答tures of a regular Store Engine like InnoDB, etc

Is there any way to tell Hibernate use MySql Memory Storage Engine?

Thanks.

Edit: I found Memory Storage Engine does not support all fea开发者_运维问答tures of a regular Store Engine like InnoDB, etc. So it may be seemed logical that there is no option for it.


There should be a properties file where you can put your URL to MySQL

#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_class com.mysql.jdbc.Driver
#hibernate.connection.url jdbc:mysql:///mysqlURL
#hibernate.connection.username
#hibernate.connection.password

But be aware of this

When using the MyISAM storage engine, MySQL uses extremely fast table locking that allows multiple readers or a single writer. The biggest problem with this storage engine occurs when you have a steady stream of mixed updates and slow selects on a single table. If this is a problem for certain tables, you can use another storage engine for them.


The storage engine used by mySQL is declared when you create your tables. Use the qualifier ENGINE=MEMORY at the end of your CREATE TABLE DDL. Then use it like any other table.

But, of course, remember that if your mySQL server bounces for any reason, all rows will be gone from that MEMORY table when it comes back.


Why do you want in-memory storage?

My personal use case scenario for such a setup is testing.

Think about using h2, hsql or derby. AFAIK they all provide in-memory storage. And if you consistently use Hibernate, it should make no difference which database runs in the background -- at least not from a development standpoint.

0

精彩评论

暂无评论...
验证码 换一张
取 消