Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I would like to have your opinion, how I can handle the case when PDO engine and Hibernate engine "talk" to the same db? There is a PHP application as frontend, and a Java doing some job after user through PHP says so.

So can we avoid concurrent access to same records? And not have problems? The database is PostgreSQL.

share|improve this question
It doesn't really matter where your connections are coming from, you'll need to research PostgreSQL's concurrency model, MVCC. –  Yannis Jun 13 '12 at 7:01
Γιάννη, Perhaps there is some kind of tutorial which I don't know of... –  hephestos Jun 13 '12 at 7:16
PostgreSQL is ACID compliant. –  Brian Jul 19 '12 at 16:56

2 Answers 2

Databases are designed to handle con-current access. You just need to remember a few things:-

  • Keep your SQL "read only" wherever possible.
  • Keep your transactions short -- save any updates till near the end of your processing and never perform any long running tasks after update but before commit.
  • Deadlocks and timeouts will occur. Just handle them sensibly, for the most part just starting a new unit of work and retring the update will do just fine.
share|improve this answer

Databases in general are made for handling multiple connections and requests at the same time through locking mechanism. The problem I might see in your scenario is more related to caching on the side of the database client applications.

Refer to the documentation of Hibernate and PDO and understand what and how their caching works.

You might want to check out JPA's @Version annotation. I don't know if PDO has a similar mechanism. If not, you'll have to implement it yourself.

Another option you have would be adding an abstraction layer between the Java side and PHP side, for instance a REST Service. So your PHP and Java clients would talk to the REST service alone and that service will handle database access for you. Has the nice advantage that you can add other client types and languages easily as long as they can talk HTTP.

share|improve this answer
And let the REST service do the CRUD operations you mean ? –  hephestos Jun 13 '12 at 8:03
REST is not the same as CRUD, don't confuse them. My main point is that database acces is coming from only one part of your system in order to avoid caching problems. REST offers a good solution for caching already if you're doing it right (tm) and you seem to be in a heterogeneous environment anyway, so having a commonly used communication protocol is a plus. –  Raku Jun 13 '12 at 8:05
I understand now what you mean. For the caching. That's a good point. How much time would it take me to make a rest service as I never did that before ? –  hephestos Jun 13 '12 at 8:31
It's hard to estimate for me because I don't know your previous programming experience. What I can suggest is that you start by reading the Wikipedia article on REST, then proceed to the HTTP spec (RFC 2616), which is very well written and easy to understand. Then try to find some tutorials on how to implement a REST service in a programming language of your choice. We're using Java and RESTEasy here. –  Raku Jun 13 '12 at 9:32
ok Raku, thanks for the suggestions –  hephestos Jun 13 '12 at 9:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.