从JPA / EclipseLink在内存中生成HSQLDB表(无文件)

时间:2012-11-01 19:56:09

标签: java jpa eclipselink hsqldb in-memory-database

我有JPA2和EclipseLink 2.4,我正在尝试使用HSQLDB实现内存数据库。我已经能够使用

创建hsqldb的文件实现
jdbc:hsqldb:file:./databases/test;shutdown=true;files_readonly=true

但是当我尝试使用jdbc:hsqldb:mem:tableName时,我收到以下消息:


堆栈跟踪:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse   
Persistence Services - 2.4.0.v20120608-r11652):  
  org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object
  not found: EFFECTIVITY

Error Code: -5501
Call: INSERT INTO EFFECTIVITY (HULL) VALUES (?)
bind => [1 parameter bound]
Query: InsertObjectQuery(101)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush
       (EntityManagerImpl.java:804)
at com.gdeb.touchtable.db.TestJPAEntities.testTTTouch(TestJPAEntities.java:93)
..............
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found:
 EFFECTIVITY
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getTable(Unknown Source)
at org.hsqldb.ParserDQL.readTableName(Unknown Source)
at org.hsqldb.ParserDQL.readRangeVariableForDataChange(Unknown Source)
at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
at org.hsqldb.Session.compileStatement(Unknown Source)
at org.hsqldb.StatementManager.compile(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 63 more

从我读到的,数据模型应该自动生成,但我只看到了Hibernate的例子。有没有办法链接JPA数据模型并使用HSQLDB的内存模式创建它?

1 个答案:

答案 0 :(得分:3)

如果表中缺少什么,则需要将eclipselink.ddl-generation属性设置为值为“create-tables”,以让Eclipselink为您创建它们。这里发布了一个示例:http://wiki.eclipse.org/EclipseLink/Examples/JPA/DDL