简体   繁体   English

大多数类似MySQL的hibernate兼容的内存数据库?

[英]Most MySQL-like hibernate-compatible in-memory database?

For a project I am working on(Spring/struts 2/hibernate), we decided to use h2 for unit testing with MySQL for the production store and manage the scheme in liquibase, pretty standard fare, but the issue we keep on running into is that h2 and MySQL differ in a lot of ways, for example how they handle timestamps and triggers. 对于我正在进行的项目(Spring / struts 2 / hibernate),我们决定使用h2进行单元测试,使用MySQL进行生产存储,并使用liquibase管理方案,非常标准的价格,但我们继续遇到的问题是h2和MySQL在很多方面有所不同,例如它们如何处理时间戳和触发器。 It's getting to the point that I am starting to regret using h2 as the extra headaches the mis-matches are causing are starting to outweigh its benefits. 我已经开始后悔使用h2因为错误匹配导致的额外麻烦开始超过它的好处。 My question is this, is there any other in-memory/local file database that behaves more like MySQL? 我的问题是,是否有任何其他内存/本地文件数据库的行为更像MySQL? Obviously for integration testing we will still use MySQL, but being able to do unit testing without either making the liquibase files into a giant hack or having to ensure the local MySQL db is running would be nice. 显然,对于集成测试,我们仍然会使用MySQL,但能够进行单元测试,而无需将liquibase文件变成一个巨大的黑客,或者必须确保本地MySQL数据库运行会很好。

I don't think there is another in-memory Java database that is more compatible to MySQL than H2. 我不认为有另一个内存中的Java数据库与MySQL的兼容性比H2更高。 If you have a lot of code that only works with MySQL, then you should probably also use MySQL for testing. 如果你有很多只适用于MySQL的代码,那么你应该也可以使用MySQL进行测试。

Just be aware that it will be difficult in the future to switch to another database. 请注意,将来很难切换到另一个数据库。 Relying too much on features of one product will result in a "vendor lock in" . 过分依赖某个产品的功能将导致“供应商锁定” In case of MySQL at least you have the option to switch to MariaDB , so it's not all that bad. 在MySQL的情况下,至少你可以选择切换到MariaDB ,所以它并不是那么糟糕。

You may use a ram drive, copy your testing tables and datas into that drive, and start your mysql configured to load from that drive, all that in a script at boot time. 您可以使用ram驱动器,将测试表和数据复制到该驱动器中,并启动配置为从该驱动器加载的mysql,在启动时脚本中的所有内容。

Then your unit tests will run insanely faster. 然后你的单元测试会疯狂地运行。 We used it for developpers workstations and the level of frustation went three steps down. 我们将它用于开发人员工作站,挫折程度降低了三步。

I think that as of right now the correct approach is to use MySQL as a Docker image. 我认为现在正确的方法是使用MySQL作为Docker镜像。

Once you create the image you can easily spin it up from your tests, and it's going to take seconds. 创建图像后,您可以轻松地从测试中将其旋转,并且需要几秒钟。 Your hibernate will dynamically initialize DB schema and there you go! 你的hibernate将动态初始化数据库架构,你就去了!

The only issue is that CI servers need to have Docker installed. 唯一的问题是CI服务器需要安装Docker。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用休眠创建内存数据库并将数据加载到 - Create in-memory database with hibernate and load data into Java内存数据库类对象 - Java in-memory database-like object 结合使用内存数据库和Hibernate教程如何执行? - Using In-memory Database With Hibernate tutorial how to execute? 将 Access 数据库数据克隆到像 H2 这样的内存数据库? - Clone Access database data to in-memory database like H2? 您能否为每个线程(用于测试)创建一个不同的 Hibernate 内存数据库? - Can you create a distinct Hibernate in-memory database for each thread (for testing)? iBatis是否与Hibernate的hbm2ddl类似,可用于与内存数据库的集成测试? - Does iBatis have any analog of Hibernate's `hbm2ddl` for integration testing with in-memory database? 使用 Spring-Boot 进行 flyway 迁移后,Hibernate 无法验证内存中的 h2 数据库 - Hibernate fails to validate in-memory h2 database after flyway migration using Spring-Boot Java中的内存数据库表 - In-memory Database Tables in java 休眠:实体词汇(内存中) - Hibernate: Entities vocabulary(in-memory storage) 如何使用Hibernate将数据流式传输到数据库BLOB(在byte []中没有内存存储) - How to stream data to database BLOB using Hibernate (no in-memory storing in byte[])
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM