2

我开发了一些单元测试,尝试连接到 Derby 内部数据库,但得到以下结果:

警告:本地异常堆栈:异常 [EclipseLink-4002](Eclipse 持久性服务 - 2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.DatabaseException 内部异常:java.sql.SQLSyntaxErrorException:表/视图“序列”不存在。错误代码:20000 调用:UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? 哪里 SEQ_NAME = ?bind => [2 个参数绑定] 查询:DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?") at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java :333) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor 的 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644)。在 com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214) 在 com.sun.intercept(BaseContainer.java:5348) 在 com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5360) .ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) at $Proxy113.createVehicle(Unknown Source) at com.thevehiclelist.__EJB31_Generated_ VehicleEJB _Intf_ Bean103) 在 org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74) 引起:java.sql.SQLSyntaxErrorException:表/视图“SEQUENCE”不存在。在 org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source) 在 org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) 在 org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException (未知来源) org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(未知来源) org.apache.derby.impl.jdbc.EmbedConnection.handleException(未知来源) org.apache.derby.impl.jdbc .ConnectionChild.handleException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedPreparedStatement.(Unknown Source) at org.apache.derby.impl.jdbc.EmbedPreparedStatement20。ConnectionWrapper40.prepareStatement(ConnectionWrapper40.java:173) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1474) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java: 1423) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:697) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:585) ... 86 更多由:java.sql.SQLException:表/视图'SEQUENCE'不存在。在 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source) ... 108 更多原因:错误 42X05:表/视图“序列”不存在。在 org.apache.derby.iapi.error.StandardException.newException(Unknown Source) at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(Unknown Source) at org.apache.derby.impl.sql.compile .FromBaseTable.bindNonVTITables(Unknown Source) at org.apache.derby.impl.sql.compile.FromList.bindTables(Unknown Source) at org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(Unknown Source) at org .apache.derby.impl.sql.compile.DMLStatementNode.bindTables(Unknown Source) at org.apache.derby.impl.sql.compile.UpdateNode.bindStatement(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。

我的 persistence.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="carcmsPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/__default</jta-data-source>

        <class>se.while_se.Book</class>
        <class>se.while_se.Car</class>
        <class>com.thevehiclelist.Vehicle</class>



        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:derby:MyTestDb;create=true" />
            <property name="javax.persistence.jdbc.user" value="" />
            <property name="javax.persistence.jdbc.password" value="" />
            <!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->

        </properties>
    </persistence-unit>
</persistence>

我的 pom.xml 是这样的:

<dependencies>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>4.8.1</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>javax.persistence</artifactId>
                    <version>2.0.0</version>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>eclipselink</artifactId>
                    <version>2.3.2</version>
                </dependency>
                <dependency>
                    <groupId>org.glassfish.main.extras</groupId>
                    <artifactId>glassfish-embedded-all</artifactId>
                    <version>3.1.2</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.apache.derby</groupId>
                    <artifactId>derby</artifactId>
                    <version>10.8.2.2</version>
                    <scope>provided</scope>
                </dependency>

            </dependencies>

似乎数据库不是在内部数据库中创建的,还是我在这里遗漏了什么?

最好的祝福

4

1 回答 1

3

以下被注释掉。因此,预计不会创建表和其他数据库对象(例如序列)。

<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->

只需删除评论,它应该可以正常工作:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> 

就像附加说明一样,拥有create=trueJDBC 连接字符串不会影响这一点。它只是关于创建数据库本身,而不是其中的表和其他对象。

于 2012-07-01T13:26:53.650 回答