In Grails I can create domain objects to a H2 in memory dataSource in BootStrap and get results back ok, but once the app is up (eg query from GSP or contro
H2 closes the database when the last connection is closed. For an in-memory database, closing the connection means the data is lost...
So if you keep one connection open all the time, then you should be fine. You could call this a 'sentinel' connection.
Another option is to use a persistent database (database URL jdbc:h2:~/test/app_data;MVCC=TRUE
)
most inmemory database tie the database to the connection used. Hibernate opens a connection for each session so only the session with the SchemaExport has the database with the correct schema and is disposed immediatly. to solve this you have to use the same connection for all sessions which access the inmemory database.
connection = session.getConnection();
sessionfactory.openSession(connection);