Search code examples
javamultithreadinghibernateapache-mina

Does hibernate locks main thread?


I'm using hibernate together with apache mina to build Multiplayer game server. I have separate client class for each (apache mina) client, separate transaction and session.
So, the question is:

Does hibernate blocks my main thread when i'm saving my entity to database or performing huge select query?


Solution

  • Yes, your JDBC calls are synchronous so they will block until something is returned from the database, this is not specific to Hibernate.

    You could create a separate thread and handle your DB actions using that. Be warned though you will run into issues sharing entities across threads such as fetching lazy relationships.