Reputation: 495
I am trying to use hibernate with sqlite in multi-threaded application and getting SQLITE_BUSY error:
[SQLITE_BUSY] The database file is locked (database is locked)
Simplified code which reproduces error in 1 thread:
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(new Object());
session.flush();
Session session2 = sessionFactory.openSession();
session2.beginTransaction();
session2.save(new Object());
session2.getTransaction().commit();
As widely suggested i set pool_size to 1, but it didn't help
<property name="connection.pool_size">1</property>
<property name="hibernate.connection.pool_size">1</property>
packages that i use:
sqlite-jdbc: 3.8.7
hibernate: 4.3.8
Upvotes: 2
Views: 1401
Reputation: 495
Custom connection pool hibernate-c3p0 did the job. Just add to pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.7.Final</version>
</dependency>
And to hibernate.cfg.xml:
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">1</property>
Upvotes: 2