简体   繁体   English

使用Hibernate将两个或多个应用程序连接到同一个数据库

[英]Connect two or more applications to the same database using Hibernate

I am planning to build a desktop application that will use Hibernate and MySQL as its datasource. 我打算构建一个桌面应用程序,它将使用Hibernate和MySQL作为其数据源。 I would like to execute the desktop application on multiple machines but I want them all to read/write to the same MySQL database. 我想在多台机器上执行桌面应用程序,但我希望它们都能读/写同一个MySQL数据库。 Is this even possible? 这甚至可能吗? My concern is about concurrency issue when two applications is trying to access/modify the same information. 当两个应用程序试图访问/修改相同的信息时,我担心的是并发问题。 Is there an alternative solution for multiple ORM applications to have real-time database syncronisation (if a single database is not allowed)? 是否存在多个ORM应用程序的替代解决方案,以实现实时数据库同步(如果不允许单个数据库)?

There were a few similar question to mine on stackoverflow but their answers do not satisfy me. 在stackoverflow上有一些类似的问题,但他们的答案不满足我。

You can have multiple hibernate-based apps talking to the same database. 您可以让多个基于hibernate的应用程序与同一个数据库通信。 For the most part, this is pretty much the same as running multiple threads talking to the same database. 在大多数情况下,这与运行与同一数据库通信的多个线程几乎相同。

The most common problem you are likely to see will occur if your hibernate configuration is using a second-level cache. 如果您的hibernate配置使用二级缓存,则可能会出现最常见的问题。 When hibernate is configured with a second-level cache, it assumes that the cache is consistent with the underlying database. 当hibernate配置了二级缓存时,它假定缓存与底层数据库一致。 When you have a single application attaching to the database, the second-level cache can exist in the local RAM of the app server and everything is good. 当您将单个应用程序附加到数据库时,二级缓存可以存在于应用程序服务器的本地RAM中,一切都很好。

If you have multiple servers (whether they are running the same application or different ones), you need to have a single second-level cache that is shared by all of the servers. 如果您有多个服务器(无论它们是运行相同的应用程序还是不同的应用程序),您需要拥有一个由所有服务器共享的单个二级缓存。 Or you need to not use a second-level cache. 或者您不需要使用二级缓存。

Several distributed cache solutions for hibernate's second-level cache are available - google will help you research your various options if you decide to go this route. 可以使用几种用于hibernate二级缓存的分布式缓存解决方案 - 如果您决定采用这种方式,谷歌将帮助您研究各种选项。

Same argument applies to query cache as well. 同样的参数也适用于查询缓存。

暂无
暂无

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

相关问题 使用Hibernate从两个不同的Web应用程序(GXT)连接同一数据库 - Connecting the same database from two different web applications(GXT) using Hibernate 两个应用程序在Hibernate Search中使用相同的索引文件 - Two Applications using the same index file with Hibernate Search 当两个单独的应用程序使用同一个数据库时,Hibernate的一级缓存结果是否过时? - Can Hibernate first level cache results be stale when two separate applications consumes same database? 使用 hibernate 在不同的应用程序上更新同一个表 - Updating the same table on the different applications using hibernate Hibernate:在同一个应用程序中使用两个不同的DataBase模式 - Hibernate: Using two different DataBase schemas in the same application 2 使用不同 hibernate 版本但相同 oracle 数据库的应用程序抛出唯一约束错误 - 2 Applications using different hibernate versions but same oracle database throwing unique constraint error 两个不同的Java应用程序共享同一个数据库 - Two different Java applications sharing the same database Hibernate使用相同的表连接到多个数据库 - Hibernate connect to multiple database with same tables 无法使用Hibernate连接两个不同的数据库 - Unable to connect two different database with Hibernate 如何使用Spring + Hibernate开发可同时在多个数据库上运行的应用程序? - How can I develop an application which will run on more than one database at a same time using Spring + Hibernate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM