gvdm
gvdm

Reputation: 3166

Is it possibile to access a Hibernate managed DB without Hibernate too?

I use Hibernate to manage a DB table and everything works just well.

Now, another system should access the same DB table and I cannot tell it to use Hibernate (because is a monolithic piece of software). My doubt concerns the correct usage of the DB from an external software and the consistency problems this approach brings to my attention. In particular, can it be a problem? Maybe Hibernate works in RAM (an ORM can implement caching and lazy transaction to speed up the write/read process) so a possible external transaction onto the DB may bring inconsistency in the Hibernate work. Is this the Hibernate case?

Thank you

Upvotes: 0

Views: 138

Answers (3)

jwenting
jwenting

Reputation: 5663

As the other answers point out, to the database it doesn't matter. However, your application is another matter entirely.
By default Hibernate does not deal nicely with data changes outside of its control. More specifically, it tends to ignore such changes completely.
As a result, the data your application has loaded will quite likely get out of synch with what the database itself knows it to be, leading to all kind of problems.
That's because Hibernate caches data, a lot of data, and tends to operate on that cache rather than the actual data for increased performance, synchronising with the database only when a transaction is committed. If something else changed the data Hibernate will blissfully ignore those changes and overwrite whatever that other process did, probaly without even giving you a warning.

Upvotes: 1

Petr Mensik
Petr Mensik

Reputation: 27516

It absolutely doesn't matter how are you accessing the DB (either through ORM, JDBC or some other connector), only thing that does matter is how your DB will handle multiple connections by different systems (so you might want to take a look at stuff like Transaction isolation).

Upvotes: 1

Mingtao Zhang
Mingtao Zhang

Reputation: 148

It shouldn't. You'd better do some integration-test.

  1. Database has another layer of consistency guarantee.
  2. Hibernate should deal with its caching 'correctly'.

Upvotes: 0

Related Questions