Jpa OpenEJB&x2B;EclipseLink无法在HSQL数据库上创建表
我有一个使用javaeeweb概要文件的vanillamavenwar项目,它使用OpenEJB执行单元/集成测试。在OpenEJB启动期间,OpenEJB不使用jndi.properties中定义的数据源,而是创建自己的:Jpa OpenEJB&x2B;EclipseLink无法在HSQL数据库上创建表,jpa,eclipselink,openejb,Jpa,Eclipselink,Openejb,我有一个使用javaeeweb概要文件的vanillamavenwar项目,它使用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=Def
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'
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();
}
}
}
看起来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"/>
这解决了有关类型的问题,但它没有解释为什么在jndi.properties中已经定义了数据源时仍然创建数据源(我还尝试通过properties对象通过programmaticaly这样做)。我不知道OpenEJB为什么会这样做。最好把这个问题分成一个单独的问题。
<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"/>
@Column(columnDefinition="NUMERIC")