0

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

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.

francis
  • 5,889
  • 3
  • 27
  • 51
  • Whoa. Seriously, there are issue in Hibernate with sharing entities across threads? Could point to documentation on that? – markspace Feb 17 '16 at 15:56
  • @markspace Sessions are not thread safe, though reattaching entities is not impossible. For write operations where you do not care about the result you won't have an issue. https://pveentjer.wordpress.com/2007/02/19/sharing-hibernate-entities-between-threads/, http://stackoverflow.com/questions/32549386/modifying-hibernate-entities-from-multiple-threads – francis Feb 17 '16 at 19:16