2

Sorry to ask this in case it has been answered before, but I heard (from a potential other noob) that Hibernate has/had some kind of connection pool manager that also handles locking of the database. Now I read this was abolished in Hibernate 3 so I, as a noob, am very confused what to use.

I have a Postgresql db with multiple clients that each use max. one db connection at any given time. I use JDBC but want to move to Hibernate.

So in case two concurrent update operations occur, I don't know if this is handled by the DBMS correctly. I thought about locking a db table manually in case someone operates on it, but there must be a better way.

I only operate with simple, single sql-statements, sometimes prepared statements. No big updates, just single line updates.

Do you have any idea how this, generally, is to be solved? Is this even a problem?

5
  • This could be covered by the database/hibernate/jdbc transaction capabilities...but yes, hibernate can support connection pooling (having only recently started using it, I'm using C3P0) but this shouldn't concern you as pooling will make the application run faster... Commented Aug 5, 2014 at 1:13
  • does the hibernate transaction add some kind of timestamp or handshake with the database so the database will ignore the concurrent connection from the other client? do i have to use special settings/java code for that? (there will not be more than 10 clients a t any given time, so I guess you are right, connection pooling would probably not be necessary, unless its possible to pool single db tables aswell)
    – javanoob
    Commented Aug 5, 2014 at 1:28
  • A transaction guarantees isolation of change (or atomic change), that is, all the changes made within a given transaction will not be committed to the database until the transaction is committed. Commented Aug 5, 2014 at 1:31
  • Yes thanks for clarification. I always thought this may be better for role-back purposes and data consistency and not necessary does prevent two transactions to the db at the same time. I am only speaking theoretically here. Probably only one commit can be executed at any given time at the db, right? So I just have use transactions in any way and will be good?
    – javanoob
    Commented Aug 5, 2014 at 1:47
  • At some point, the DB must perform some of lock to ensure that the data is managed within the DB itself correctly Commented Aug 5, 2014 at 1:50

1 Answer 1

2

This is too general for a truly useful answer, and I should really just close-vote it. But I'll try to help.

The connection pool has nothing to do with locking. The two are unrelated topics.

I think you're vaguely trying to refer to the optimistic concurrency control in Hibernate. This is an alternative strategy to normal row locking, with a different set of advantages and disadvantages.

See the Hibernate documentation for more information, and the wikipedia article on optimistic concurrency control.

I also wrote a recent blog entry on this topic that may be useful.

Above all else, though, there's no substitute for actually understanding concurrency in the application and database. I very strongly recommend reading the PostgreSQL documentation chapter on concurrency control in detail.

5
  • thanks for helping out a noob :) I thought my problem may be solved already by a version of jdbc or hibernate as they are very advanced technologies and was not able to verify. I learned a lot and will do the reading thanks to your guidance.
    – javanoob
    Commented Aug 5, 2014 at 1:51
  • @javanoob In future it'd be very helpful if you tried to illustrate your questions with examples. Commented Aug 5, 2014 at 1:54
  • yes, you are right. I learned that your blog actually covers strategies for more complex sql operations while for my simple purposes, that would have been illustrated by an example, using transactions would be enough in most cases. still I am grateful to have a much better overview. thanks again
    – javanoob
    Commented Aug 5, 2014 at 2:05
  • @javanoob If you found the question is useful you might consider giving it an upvote (little up arrow above the number). If you found it answered your question, you might consider marking it as correct (little outline of a tick mark below the number and arrows) Commented Aug 5, 2014 at 2:14
  • 1
    thanks. cant do more than setting it correctly as i need to wait 8 hours before answering myself and more than 15 reputation to upvote. thanks also for explaining to me about transactions.
    – javanoob
    Commented Aug 5, 2014 at 2:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.