OpenEJB + EclipseLink无法在HSQL数据库上创建表

时间:2013-08-05 15:50:50

标签: jpa eclipselink openejb

我有一个使用Java EE Web配置文件的vanilla maven WAR项目,该项目使用OpenEJB执行其单元/集成测试。在OpenEJB启动期间,OpenEJB不是使用jndi.properties中定义的数据源,而是创建自己的数据源:

INFO - Auto-creating a Resource with id 'Default JDBC Database' of type 'DataSource for 'scmaccess-unit'.
INFO - Creating Resource(id=Default JDBC Database)
INFO - Configuring Service(id=Default Unmanaged JDBC Database, type=Resource, provider-id=Default Unmanaged JDBC Database)
INFO - Auto-creating a Resource with id 'Default Unmanaged JDBC Database' of type 'DataSource for 'scmaccess-unit'.
INFO - Creating Resource(id=Default Unmanaged JDBC Database)
INFO - Adjusting PersistenceUnit scmaccess-unit <jta-data-source> to Resource ID 'Default JDBC Database' from 'jdbc/scmaccess'
INFO - Adjusting PersistenceUnit scmaccess-unit <non-jta-data-source> to Resource ID 'Default Unmanaged JDBC Database' from 'null'

然后,在下面,当创建表时 - 根据应用程序的persistence.xml文件中定义的create-drop策略 - 我看到了几个这样的错误:

(...) Internal Exception: java.sql.SQLSyntaxErrorException: type not found or user lacks privilege: NUMBER
Error Code: -5509

jndi.properties文件:

##
# Context factory to use during tests
##
java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory

##
# The DataSource to use for testing
##
scmDatabase=new://Resource?type=DataSource
scmDatabase.JdbcDriver=org.hsqldb.jdbcDriver
scmDatabase.JdbcUrl=jdbc:hsqldb:mem:scmaccess

##
# Override persistence unit properties
##
scmaccess-unit.eclipselink.jdbc.batch-writing=JDBC
scmaccess-unit.eclipselink.target-database=Auto
scmaccess-unit.eclipselink.ddl-generation=drop-and-create-tables
scmaccess-unit.eclipselink.ddl-generation.output-mode=database

而且,测试用例:

public class PersistenceTest extends TestCase {

    @EJB
    private GroupManager ejb;

    @Resource
    private UserTransaction transaction;

    @PersistenceContext
    private EntityManager emanager;

    public void setUp() throws Exception {
        EJBContainer.createEJBContainer().getContext().bind("inject", this);
    }

    public void test() throws Exception {
        transaction.begin();
        try {
            Group g = new Group("Saas Automation");
            emanager.persist(g);
        } finally {
            transaction.commit();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

看起来eclipselink正在尝试创建类型为NUMBER的列,并且该类型在HSQL中不存在。您是否在映射中指定了该类型?如果是,那么解决它。

否则可能有助于添加

    <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
    <property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/>
    <property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/>
    <property name="eclipselink.ddl-generation.output-mode" value="both"/>

到你的persistence.xml,这样你就可以看到创建了哪些create table语句。如果eclipselink对某些列使用NUMBER,则可以通过在相应字段上使用以下注释告诉它使用其他内容。

@Column(columnDefinition="NUMERIC")