内部 HSQL 数据库抱怨权限
我正在设置一个独立的Java服务,其中包含一个进程内内存中的HSQL数据库。
持久性.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.silvercar.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>
法典
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);
在我看来,由于数据库在内存中,而Hibernate应该生成表,因此我不需要执行任何其他操作。但是,在调用时,我得到异常:getSingleResult
org.hsqldb.HsqlException: user lacks privilege or object not found: USER