2013-08-05 64 views
0

我有一個使用Java EE web配置文件的vanilla maven WAR項目,它使用OpenEJB執行其單元/集成測試。在OpenEJB的啓動,而不是使用在jndi.properties中定義的數據源,OpenEJB的創建自己:OpenEJB + EclipseLink無法在HSQL數據庫上創建表格

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' 

,然後進一步在下面,當它的時間來創建表 - 爲每create-拖放到應用程序的persistence.xml文件中定義的策略 - 我看到這樣幾個誤區:

(...) 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

看起來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") 
+0

這解決了關於類型的問題,但它並不能解釋爲什麼當一個人在jndi.properties已經定義仍然是創建數據源(我也試着這樣做pro​​grammaticaly,通過Properties對象) 。 – javabeats

+0

我不知道爲什麼OpenEJB會這樣做。將這個問題分解爲一個單獨的問題可能會更好。 – Eelke