Reputation: 5850
Below is my scenario: My application begins a transaction, inserts/updates and then calls a web service. There is a possibility that the web service takes long to process the request. Is there any way to configure a time out for my session/ transaction in my hibernate layer so that i can gracefully close the session. P.S. - Alternatively i can also look to configure a time out for my web service call.Assume that i dont have that liberty. Is there anything i can do in Hibernate or do i need to write my own custom logic (using threads join constructs) to implement these
Upvotes: 3
Views: 13949
Reputation: 22672
You can set timeout at the level of particular query or if you use JPA's EntityManager you can add query hint.
The theory is that Hibernate uses by default optimistic locking (if database transaction isolation level conforms to that), so records are never locked againts writes or reads. As a result, even long lasting transaction should not hurt performance badly.
If you are using pesimistic lock, you can set timeout for them in Hibernate Session. Look at Session.LockRequest.
Upvotes: 3