0

我有一个使用 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();
        }
    }
}
4

1 回答 1

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,这样您就可以看到究竟生成了什么创建表语句。如果 eclipselink 对某些列单独使用 NUMBER,您可以通过在相应字段上使用以下注释来告诉它使用其他内容。

@Column(columnDefinition="NUMERIC")
于 2013-08-05T19:20:07.530 回答