user1016403
user1016403

Reputation: 12621

Exception if no transactions are configured?

I am using spring/hibernate stand alone application. if i dont configure Transactions i am getting below excpetion.

Exception in thread "Thread-1" org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

in spring/hibernate integrated application is it mandatory to have transaction configuration?

Thanks!

Upvotes: 0

Views: 47

Answers (1)

JB Nizet
JB Nizet

Reputation: 692181

Basically, yes. The Hibernate documentation says:

Database, or system, transaction boundaries are always necessary. No communication with the database can occur outside of a database transaction (this seems to confuse many developers who are used to the auto-commit mode). Always use clear transaction boundaries, even for read-only operations. Depending on your isolation level and database capabilities this might not be required, but there is no downside if you always demarcate transactions explicitly. Certainly, a single database transaction is going to perform better than many small transactions, even for reading data.

Upvotes: 2

Related Questions