我尝试连接到Derby内部数据库时开发了一些单元测试,但得到以下内容:
警告:本地异常堆栈:异常[EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException内部 例外:java.sql.SQLSyntaxErrorException:Table / View' SEQUENCE' 不存在。错误代码:20000呼叫:更新序列集SEQ_COUNT = SEQ_COUNT +?在哪里SEQ_NAME =? bind => [2个参数绑定]查询:DataModifyQuery(name =" SEQUENCE" sql =" UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT +?在哪里SEQ_NAME =?")at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644) 在 org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535) 在 org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717) 在 org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253) 在 org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207) 在 org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193) 在 org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelectCall(DatasourceCallQueryMechanism.java:236) 在 org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelect(DatasourceCallQueryMechanism.java:216) 在 org.eclipse.persistence.queries.DataModifyQuery.executeDatabaseQuery(DataModifyQuery.java:85) 在 org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844) 在 org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2831) 在 org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1516) 在 org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1498) 在 org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1463) 在 org.eclipse.persistence.sequencing.QuerySequence.update(QuerySequence.java:340) 在 org.eclipse.persistence.sequencing.QuerySequence.updateAndSelectSequence(QuerySequence.java:277) 在 org.eclipse.persistence.sequencing.StandardSequence.getGeneratedVector(StandardSequence.java:71) 在 org.eclipse.persistence.sequencing.DefaultSequence.getGeneratedVector(DefaultSequence.java:163) 在 org.eclipse.persistence.sequencing.Sequence.getGeneratedVector(Sequence.java:257) 在 org.eclipse.persistence.internal.sequencing.SequencingManager $ Preallocation_Transaction_NoAccessor_State.getNextValue(SequencingManager.java:468)at at org.eclipse.persistence.internal.sequencing.SequencingManager.getNextValue(SequencingManager.java:1067) 在 org.eclipse.persistence.internal.sequencing.ClientSessionSequencing.getNextValue(ClientSessionSequencing.java:70) 在 org.eclipse.persistence.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:349) 在 org.eclipse.persistence.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:308) 在 org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.assignSequenceNumber(UnitOfWorkImpl.java:465) 在 org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:4231) 在 org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:513) 在 org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4176) 在 org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:440) 在 com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:269) 在com.thevehiclelist.VehicleEJB.createVehicle(VehicleEJB.java:32) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:601)at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052) 在 org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124) 在 com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388) at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619) 在 com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800) 在com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162) 在 com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:601)at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861) 在 com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800) 在 com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370) 在 com.sun.ejb.containers.BaseContainer。的截距(BaseContainer.java:5360) 在 com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348) 在 com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214) 在 com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88) 在$ Proxy113.createVehicle(未知来源)at com.thevehiclelist .__ EJB31_Generated_ VehicleEJB _Intf _ 豆 _。createVehicle(未知 来源)at com.thevehiclelist.VehicleTest.shouldCreateAVehicle(VehicleTest.java:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:601)at org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:44) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 在 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 在 org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:193)at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:52)at at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)at at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:42)at at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:184)at at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 在 org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 在org.junit.runners.ParentRunner.run(ParentRunner.java:236)at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:236) 在 org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134) 在 org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:601)at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) 在 org.apache.maven.surefire.booter.ProviderFactory $ ProviderProxy.invoke(ProviderFactory.java:165) 在 org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) 在 org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103) 在 org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74) 引起:java.sql.SQLSyntaxErrorException:表/视图' SEQUENCE' 不存在。在 org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(未知 来源)at org.apache.derby.impl.jdbc.Util.generateCsSQLException(未知来源) 在 org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(未知 来源)at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(未知 来源)at org.apache.derby.impl.jdbc.EmbedConnection.handleException(未知 来源)at org.apache.derby.impl.jdbc.ConnectionChild.handleException(未知 来源)at org.apache.derby.impl.jdbc.EmbedPreparedStatement。(未知 来源)at org.apache.derby.impl.jdbc.EmbedPreparedStatement20。(未知 来源)at org.apache.derby.impl.jdbc.EmbedPreparedStatement30。(未知 来源)at org.apache.derby.impl.jdbc.EmbedPreparedStatement40。(未知 来源)at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(未知 来源)at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(未知 来源)at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(未知 来源)at com.sun.gjc.spi.base.ConnectionHolder.prepareStatement(ConnectionHolder.java:562) 在 com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareCachedStatement(ConnectionWrapper40.java:255) 在 com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareCachedStatement(ConnectionWrapper40.java:52) 在 com.sun.gjc.spi.ManagedConnection.prepareCachedStatement(ManagedConnection.java:993) 在 com.sun.gjc.spi.jdbc40.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(未知 来源)at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(未知 来源)... 108更多引起:错误42X05:表/视图' SEQUENCE' 不存在。在 org.apache.derby.iapi.error.StandardException.newException(未知 来源)at org.apache.derby.impl.sql.compile.FromBaseTable.bindTableDescriptor(未知 来源)at org.apache.derby.impl.sql.compile.FromBaseTable.bindNonVTITables(未知 来源)at org.apache.derby.impl.sql.compile.FromList.bindTables(未知来源) 在 org.apache.derby.impl.sql.compile.SelectNode.bindNonVTITables(未知 来源)at org.apache.derby.impl.sql.compile.DMLStatementNode.bindTables(未知 来源)at org.apache.derby.impl.sql.compile.UpdateNode.bindStatement(未知 来源)at org.apache.derby.impl.sql.GenericStatement.prepMinion(未知来源) 在org.apache.derby.impl.sql.GenericStatement.prepare(未知来源) 在 org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(未知 来源)... 102更多
我的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>
似乎数据库不是在内部数据库中创建的,或者我在这里遗漏了什么?
祝你好运
答案 0 :(得分:3)
以下内容已被注释掉。因此,预计不会创建表和其他数据库对象(例如序列)。
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
只需删除评论即可正常使用:
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
另外注意,在JDBC连接字符串中使用create=true
不会影响这一点。它只是关于创建数据库本身,而不是创建表和其他对象。