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();
}
}
}
這解決了關於類型的問題,但它並不能解釋爲什麼當一個人在jndi.properties已經定義仍然是創建數據源(我也試着這樣做programmaticaly,通過Properties對象) 。 – javabeats
我不知道爲什麼OpenEJB會這樣做。將這個問題分解爲一個單獨的問題可能會更好。 – Eelke