SQLite vs HSQLDB

SQLite is implemented in C, HSQL is implemented in Java. It should be more seamless and easy to integrate SQLite with an application project written in C or C++, whereas I would expect the HSQL technology is easier to integrate with a project written in Java. No doubt there are numerous other more subtle differences … Read more

How to see all the tables in an HSQLDB database?

The ANSI SQL92 standard for querying database metadata is contained within the INFORMATION_SCHEMA data structures. I have no idea whether your database supports this or not, but try the following: SELECT * FROM INFORMATION_SCHEMA.TABLES On further research, it appears that HSQLDB does support INFORMATION_SCHEMA, but with slightly non-standard naming. All of the tables have SYSTEM_* … Read more

How do I reset my database state after each unit test without making the whole test a transaction?

Since you are using Hibernate, you could use the property hibernate.hbm2ddl.auto to create the database on startup every time. You would also need to force the spring context to be reloaded after each test. You can do this with the @DirtiesContext annotation. This might add a bit extra overhead to your tests, so the other … Read more

Inspect in memory hsqldb while debugging

In your unit test or in the @Before / setUp() method, you can add the following line to launch the HSQL Database Manager: org.hsqldb.util.DatabaseManager.main(new String[] { “–url”, “jdbc:hsqldb:mem:testdb”, “–noexit” }); or for the improved Swing version with “more refinements” (but about same functionality) org.hsqldb.util.DatabaseManagerSwing.main(new String[] { “–url”, “jdbc:hsqldb:mem:testdb”, “–noexit” }); The DB manager lets you … Read more

Unsuccessful: alter table XXX drop constraint YYY in Hibernate/JPA/HSQLDB standalone

You can ignore these errors. Combination of create-drop and empty (which is the case always for in-memory) database produces these for every database object it tries to drop. Reason being that there is not any database objects to remove – DROP statements are executed against empty database. Also with normal permanent database such a errors … Read more

How do you reset Spring JUnit application context after a test class dirties it?

Use @DirtiesContext to force a reset. For example I have: @ContextConfiguration(classes={BlahTestConfig.class}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class SomeTest { @Autowired XXXX xx; @Autowired YYYY yy; @Before public void setUp() { MockitoAnnotations.initMocks(this); when(YYYY.newYY()).thenReturn(zz); } @Test public void testSomeTest() { XX.changeSomething(“StringTest”); XX.doSomething(); check_for_effects(); } @Test public void testSomeOtherTest() { XX.changeSomething(“SomeotherString”); XX.doSomething(); check_for_effects(); } From spring docs DirtiesContext Indicates … Read more

Huge performance difference when using GROUP BY vs DISTINCT

The two queries express the same question. Apparently the query optimizer chooses two different execution plans. My guess would be that the distinct approach is executed like: Copy all business_key values to a temporary table Sort the temporary table Scan the temporary table, returning each item that is different from the one before it The … Read more