0

OpenEJB を使用してユニット/統合テストを実行する、Java EE Web プロファイルを使用するバニラ maven WAR プロジェクトがあります。OpenEJB の起動時に、jndi.properties で定義されたデータ ソースを使用する代わりに、OpenEJB は独自のデータ ソースを作成します。

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"/>

これにより、どの create table ステートメントが正確に生成されたかを確認できます。eclipselink が特定の列に対して単独で NUMBER を使用している場合は、対応するフィールドで次の注釈を使用して、別のものを使用するように指示できます。

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