I'm setting up a standalone Java service with an in-process, in-memory HSQL database.
Persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="manager">
<class>tr.altinstar.data.entities.User</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:testdb" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<!-- cache configuration -->
<!--
<property name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item"
value="read-write" />
<property
name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors"
value="read-write, RegionName" />
-->
</properties>
</persistence-unit>
</persistence>
Code
emf = Persistence.createEntityManagerFactory("manager");
User newUser = new User();
newUser.setName("Testgebruiker");
newUser.setCredits(100);
System.out.println("Inserting user");
EntityManager em = emf.createEntityManager();
em.persist(newUser);
em.close();
System.out.println("Getting user");
em = emf.createEntityManager();
User u = (User) em.createQuery("SELECT u FROM User u").getSingleResult();
em.close();
System.out.println(u);
It would seem to me that since the database is in memory, and Hibernate should generate tables, that I don't need to do anything else. However, upon calling getSingleResult
I get the exception:
org.hsqldb.HsqlException: user lacks privilege or object not found: USER