0

您好,我尝试在测试之前创建我的数据库方案,但它失败了:/这是我的脚本:

CREATE TABLE OFCONVERSATION
(
  CONVERSATIONID integer NOT NULL,
  ROOM character varying(1024),
  ISEXTERNAL smallint NOT NULL,
  STARTDATE bigint NOT NULL,
  LASTACTIVITY bigint NOT NULL,
  MESSAGECOUNT integer NOT NULL,
  CONSTRAINT OFCONVERSATION_PK PRIMARY KEY (CONVERSATIONID)
);

当我尝试使用 squirell 和嵌入式 derby 运行该脚本时,它的工作原理。

  1. 首先我尝试在类测试之前使用注释 @CreateSchema("scripts/import.sql") :
  2. 下次尝试使用@ApplyScriptBefore
  3. 第二我尝试使用脚本:

属性名称="scriptsToExecuteBeforeTest" 脚本/import.sql 属性

但这一切都失败了...

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 9.816 sec <<< FAILURE!
getPairChat(com.test.ejb.im.service.impl.PairChatTest)  Time elapsed: 0.451 sec  <<< ERROR!
org.jboss.arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Unable to execute statement: CREATE TABLE OFCONVERSATION
(
CONVERSATIONID integer NOT NULL,
ROOM character varying(1024),
ISEXTERNAL smallint NOT NULL,
STARTDATE bigint NOT NULL,
LASTACTIVITY bigint NOT NULL,
MESSAGECOUNT integer NOT NULL,
CONSTRAINT OFCONVERSATION_PK PRIMARY KEY (CONVERSATIONID)
);
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
    at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source

这是我的 arquillian pom 导入:

    <dependency>
      <groupId>org.glassfish.main.extras</groupId>
      <artifactId>glassfish-embedded-all</artifactId>
      <version>${glassfish-embedded-all.version}</version>
      <type>jar</type>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>  

    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
        <version>1.0.0.CR3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.arquillian.extension</groupId>
        <artifactId>arquillian-persistence-impl</artifactId>
        <version>1.0.0.Alpha6</version>
        <scope>test</scope>
    </dependency>

和我的 test-persistence.xml:

 <persistence-unit name="test-ejb" transaction-type="JTA">
  <jta-data-source>test-ds</jta-data-source>
  <exclude-unlisted-classes>false</exclude-unlisted-classes>      
  <properties>
      <property name="eclipselink.target-database" value="DERBY"/>
      <property name="eclipselink.platform.class.name" value="org.eclipse.persistence.platform.database.DerbyPlatform"/>
       <!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> --> 
      <property name="eclipselink.logging.level" value="ALL"/>
      <property name="eclipselink.jpa.uppercase-column-names" value="true" />
  </properties>
  </persistence-unit>

和 glassfish-resources.xml:

<resources>
    <jdbc-connection-pool name="test-pool"
        res-type="javax.sql.DataSource" datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"
        ping="true">
        <property name="ConnectionAttributes" value="create=true" />
        <property name="DatabaseName" value="./target/derbydb" />
        <property name="Password" value="" />
        <property name="User" value="" />
    </jdbc-connection-pool>
    <jdbc-resource jndi-name="test-ds" pool-name="test-pool" />
</resources>

那么那个 sql 脚本或我的配置有什么问题?

4

2 回答 2

0

如果你得到(或与你使用 Derby 类似的东西):

Caused by: java.sql.SQLException: ORA-00911: invalid character

在您的堆栈跟踪中进一步向下,那么您可能偶然发现了Alpha6 中的一个损坏的功能

于 2013-09-20T08:27:42.597 回答
0

这将对您有所帮助,因为我删除了特殊字符(回车,换行......)

CREATE TABLE OFCONVERSATION(  CONVERSATIONID integer NOT NULL,  ROOM character varying(1024),  ISEXTERNAL smallint NOT NULL,  STARTDATE bigint NOT NULL,  LASTACTIVITY bigint NOT NULL,  MESSAGECOUNT integer NOT NULL,  CONSTRAINT OFCONVERSATION_PK PRIMARY KEY (CONVERSATIONID))
于 2014-04-16T10:23:39.633 回答