Alex Rivera | Logout

HSQLDB and Hibernate/JPA - not persisting to disk?

Asked 2010-08-23T21:50:46.457
26

Something of an novice with HSQL and Hibernate...

em.getTransaction().begin();
for (Activity theActivity : activities) {
  em.persist(theActivity);
}
em.getTransaction().commit();
em.close();

followed by...

EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
System.out.println("QUERY:: "
    + em.createQuery("SELECT COUNT(*) FROM " + Activity.class.getName()).getSingleResult()
        .toString());
em.getTransaction().commit();

Prints 25000 (the number of Activity objects in activities). But when I run this test again, the number of objects in the count(*) doesn't increase (and is 0 at the beginning of the program). So the objects aren't getting durably written.

This is my hsqldb connection string:

name="hibernate.connection.url" value="jdbc:hsqldb:file:data/cmon"

so it's not an in-memory database as far as I know...

Does anyone have any ideas why the objects aren't getting persisted beyond a single JVM session? Happy to supply more information but there's so much state associated with Hibernate / JPA / HSQL that it's not clear exactly what is pertinent.

Edit
Report

1 Answer

9

The solution is :

<property name="dialect">org.hibernate.dialect.HSQLDialect</property>

in hibernate.cfg.xml


This is rest of my configuration:

Libs:

  • HsqlDb 2.0.0
  • Hibernate 3.5.6

Url:

<property name="connection.url">jdbc:hsqldb:file:data/mydb;shutdown=true;hsqldb.write_delay=false;</property>
answered 2010-09-26T22:56:10.490

Your Answer