rico
rico

Reputation: 1935

How can 2 separated web applications can share a second level cache with Hibernate?

I have 2 web applications.

I want it to access to the same shared database with Hibernate and i want to use a second level cache in each. But i want the second web application to be able to see the first web application's modifications.

I am not sure to have understood but is Hazelcast a solution for my need ?

Will i be able to manage transactions as before with Spring with that solution?

Thank you.

Upvotes: 0

Views: 273

Answers (4)

Arne Burmeister
Arne Burmeister

Reputation: 20594

So i cannot use two separated Hibernate Session Factories.

Why not? Except you have set the flush mode to MANUAL, there should be no problem. Typical setting is COMMIT or AUTO.

Any further problems can occur using a second level cache. Avoid this if your app server has no JTA environment.

PS: The hibernate settings can be configured by spring, but it can be done any other way.

Upvotes: 0

Tony318
Tony318

Reputation: 562

I think you are making this more complicated than it needs to be. Just set up both web apps to pull in data using a select statement, and whenever you modify data (using an update) on one of the page, do a post back.

This way no matter which page makes a change, the page posts back and when the other page loads the change is already there. This should also work if you are using ajax to avoid post backs.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691715

Why do you think you can't have two separate session factories? This won't cause any problem, except if you're using a non-clustered second-level cache to store read-write entities.

Upvotes: 0

Jay
Jay

Reputation: 27474

Just Do It. Any change that an application makes to a database should be visible to any other application that reads that database. Once a change is committed, it should be on the hard drive, and anybody else who reads the database from the hard drive should see it.

Upvotes: 0

Related Questions