I am planning to build a desktop application that will use Hibernate and MySQL as its datasource. I would like to execute the desktop application on multiple machines but I want them all to read/write to the same MySQL database. 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)?
There were a few similar question to mine on stackoverflow but their answers do not satisfy me.
It represents the classname of a custom ConnectionProvider which provides JDBC connections to Hibernate. It is used to set the JDBC transaction isolation level. It enables auto-commit for JDBC pooled connections.
Both Hibernate & JDBC facilitate accessing relational tables with Java code. Hibernate is a more efficient & object-oriented approach for accessing a database. However, it is a bit slower performance-wise in comparison to JDBC.
The short answer on the fundamental difference between JDBC and Hibernate is that Hibernate performs an object-relational mapping framework, while JDBC is simply a database connectivity API. The long answer requires a history lesson on database access with Java.
JDBC is database dependent i.e. one needs to write different codes for different database. Whereas Hibernate is database independent and same code can work for many databases with minor changes.
You can have multiple hibernate-based apps talking to the same database. 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. When hibernate is configured with a second-level cache, it assumes that the cache is consistent with the underlying database. 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.
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.
Same argument applies to query cache as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With