Apache Cayenne > Index > Cayenne FAQ > HSQLDB Shutdown
Added by Andrus Adamchik, last edited by Andrus Adamchik on Jun 29, 2007  (view change)

An in-process HSQLDB may cache committed data in-memory, so after a Java application exits, you may end up losing your committed data. Some users who tried Cayenne tutorials with HSQLDB ended up with empty database, even though the application reported committing a number of objects.

The solution is to explicitly shut down HSQLDB when the application exits. For instance in a command-line application main method may look like this:

public static void main(String[] args) {
    ObjectContext context = DataContext.createDataContext();

    ....

    DataMap map = (DataMap) context.getEntityResolver().getDataMaps()
		        .iterator().next();
    context.performGenericQuery(new SQLTemplate(map, "SHUTDOWN"));
}