Spring boot – derby database – GenerationTarget encountered exception accepting command : Error executing DDL "drop table wire"

huangapple go评论111阅读模式
英文:

Spring boot - derby database - GenerationTarget encountered exception accepting command : Error executing DDL "drop table wire"

问题

我是春季引导世界的新手。我不知道Maven Pom.xml文件中是否存在版本冲突。

GenerationTarget遇到异常,接受命令时出现异常:通过JDBC语句执行DDL "drop table wire"

org.hibernate.tool.schema.spi.CommandAcceptanceException:通过JDBC语句执行DDL "drop table wire"时出错
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)〜[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375)[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359)[hibernate-core-5.4.12.Final.jar:5.4.12.Final]

在运行独立的Spring Tool Suite 4.4.7.2时出现异常

Pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;>
<modelVersion>4.0.0</modelVersion>
<groupId>io.wires.springbootquickstart</groupId>
<artifactId>wires-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Wires API Sample </name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>

</dependencies>
</project>

实体文件- wire类是模型层,也称为实体层
//在MVC模式中,Wire类是模型层,也称为实体层////我们需要将Wire类的对象,换句话说,wire类的实例保存到数据库中

package io.wiresapi.springbootstarter.Wires.SendWires;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Wire {

//在MVC模式中,Wire类是模型层,也称为实体层
//我们需要将Wire类的对象,换句话说,wire类的实例保存到数据库中

public Wire() {

}

public Wire(int wireId, String lPID, float wireAmount) {
super();
this.WireId = wireId;
this.LPID = lPID;
this.WireAmount = wireAmount;
}

@Id
private int WireId;
private String LPID;
private float WireAmount;

public int getWireId() {
return WireId;
}
public void setWireId(int wireId) {
WireId = wireId;
}
public String getLPID() {
return LPID;
}
public void setLPID(String lPID) {
LPID = lPID;
}
public float getWireAmount() {
return WireAmount;
}
public void setWireAmount(float wireAmount) {
WireAmount = wireAmount;
}

}

主方法

package io.wiresapi.springbootstarter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WiresAPI {

public static void main(String[] args) {
// TODO Auto-generated method stub

  1. //SpringApplication是一个静态类
  2. SpringApplication.run(WiresAPI.class, args);

}

}

存储库文件

package io.wiresapi.springbootstarter.Wires.SendWires;

import org.springframework.data.repository.CrudRepository;

//Spring data JPA已经为所有CRUM操作提供了一个接口

public interface WireRepository extends CrudRepository<Wire,String>{

}

控制器文件

package io.wiresapi.springbootstarter.Wires.SendWires;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WiresSendController {

@Autowired
private WiresService aWireService;

//我们将客户端的传入请求映射到适当的方法。

//获取所有电线URI
@RequestMapping("/Wires")
public List TotalWiresSent() {

  1. return aWireService.getAllWires();

}

}

英文:

I am a novice in spring boot world. I don't know if it is version conflicts in the Maven Pom.xml file.

  1. GenerationTarget encountered exception accepting command : Error executing DDL &quot;drop table wire&quot; via JDBC Statement
  2. org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL &quot;drop table wire&quot; via JDBC Statement
  3. at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.12.Final.jar:5.4.12.Final]
  4. at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375) [hibernate-core-5.4.12.Final.jar:5.4.12.Final]
  5. at org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlStrings(SchemaDropperImpl.java:359) [hibernate-core-5.4.12.Final.jar:5.4.12.Final]

exception while I run my stand-alone spring tool suite 4.4.7.2

Pom.xml file

  1. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-
  2. instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-
  3. 4.0.0.xsd&quot;&gt;
  4. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  5. &lt;groupId&gt;io.wires.springbootquickstart&lt;/groupId&gt;
  6. &lt;artifactId&gt;wires-api&lt;/artifactId&gt;
  7. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  8. &lt;name&gt;Wires API Sample &lt;/name&gt;
  9. &lt;parent&gt;
  10. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  11. &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
  12. &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
  13. &lt;/parent&gt;
  14. &lt;dependencies&gt;
  15. &lt;dependency&gt;
  16. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  17. &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
  18. &lt;/dependency&gt;
  19. &lt;dependency&gt;
  20. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  21. &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  22. &lt;/dependency&gt;
  23. &lt;dependency&gt;
  24. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  25. &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
  26. &lt;/dependency&gt;
  27. &lt;dependency&gt;
  28. &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
  29. &lt;artifactId&gt;derby&lt;/artifactId&gt;
  30. &lt;/dependency&gt;
  31. &lt;/dependencies&gt;
  32. &lt;/project&gt;

Entity file- wire class is the Model layer also called the entity layer
//In a MVC pattern, the Wire class is the Model layer also called the entity layer////We need to save the objects of the Wire class in other words instances of the wire class into the

  1. package io.wiresapi.springbootstarter.Wires.SendWires;
  2. import javax.persistence.Entity;
  3. import javax.persistence.Id;
  4. @Entity
  5. public class Wire {
  6. //In a MVC pattern, the Wire class is the Model layer also called the entity layer
  7. //We need to save the objects of the Wire class in other words instances of the wire class into the database
  8. public Wire() {
  9. }
  10. public Wire(int wireId, String lPID, float wireAmount) {
  11. super();
  12. this.WireId = wireId;
  13. this.LPID = lPID;
  14. this.WireAmount = wireAmount;
  15. }
  16. @Id
  17. private int WireId;
  18. private String LPID;
  19. private float WireAmount;
  20. public int getWireId() {
  21. return WireId;
  22. }
  23. public void setWireId(int wireId) {
  24. WireId = wireId;
  25. }
  26. public String getLPID() {
  27. return LPID;
  28. }
  29. public void setLPID(String lPID) {
  30. LPID = lPID;
  31. }
  32. public float getWireAmount() {
  33. return WireAmount;
  34. }
  35. public void setWireAmount(float wireAmount) {
  36. WireAmount = wireAmount;
  37. }
  38. }

Main method

  1. package io.wiresapi.springbootstarter;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class WiresAPI {
  6. public static void main(String[] args) {
  7. // TODO Auto-generated method stub
  8. //SpringApplication is a static class
  9. SpringApplication.run(WiresAPI.class, args);
  10. }
  11. }

Repository file

  1. package io.wiresapi.springbootstarter.Wires.SendWires;
  2. import org.springframework.data.repository.CrudRepository;
  3. //Spring data JPA has already an interface for all CRUM operations
  4. public interface WireRepository extends CrudRepository&lt;Wire,String&gt;{
  5. }

Controller file

  1. package io.wiresapi.springbootstarter.Wires.SendWires;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.PathVariable;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RestController;
  11. @RestController
  12. public class WiresSendController {
  13. @Autowired
  14. private WiresService aWireService;
  15. //We map an incoming request from the client to an appropriate method.
  16. //Get all wires URI
  17. @RequestMapping(&quot;/Wires&quot;)
  18. public List&lt;Wire&gt; TotalWiresSent() {
  19. return aWireService.getAllWires();
  20. }
  21. }

Console

  1. :: Spring Boot :: (v2.2.6.RELEASE)
  2. 2020-09-26 14:50:32.465 INFO 19332 --- [ main] io.wiresapi.springbootstarter.WiresAPI
  3. : Starting WiresAPI on WN-CA14R9Y6H224 with PID 19332 (C:\Users\myname\Documents\workspace-spring-
  4. tool-suite-4-4.7.2.RELEASE\wires-api\target\classes started by bxnath1 in
  5. C:\Users\myname\Documents\workspace-spring-tool-suite-4-4.7.2.RELEASE\wires-api)
  6. 2020-09-26 14:50:32.474 INFO 19332 --- [ main] io.wiresapi.springbootstarter.WiresAPI
  7. : No active profile set, falling back to default profiles: default
  8. 2020-09-26 14:50:33.961 INFO 19332 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate :
  9. Bootstrapping Spring Data JPA repositories in DEFAULT mode.
  10. 2020-09-26 14:50:34.119 INFO 19332 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate :
  11. Finished Spring Data repository scanning in 140ms. Found 1 JPA repository interfaces.
  12. 2020-09-26 14:50:35.301 INFO 19332 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer :
  13. Tomcat initialized with port(s): 3000 (http)
  14. 2020-09-26 14:50:35.317 INFO 19332 --- [ main] o.apache.catalina.core.StandardService
  15. : Starting service [Tomcat]
  16. 2020-09-26 14:50:35.318 INFO 19332 --- [ main] org.apache.catalina.core.StandardEngine
  17. : Starting Servlet engine: [Apache Tomcat/9.0.33]
  18. 2020-09-26 14:50:35.635 INFO 19332 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] :
  19. Initializing Spring embedded WebApplicationContext
  20. 2020-09-26 14:50:35.636 INFO 19332 --- [ main] o.s.web.context.ContextLoader
  21. : Root WebApplicationContext: initialization completed in 3041 ms
  22. 2020-09-26 14:50:36.051 INFO 19332 --- [ main] com.zaxxer.hikari.HikariDataSource
  23. : HikariPool-1 - Starting...
  24. 2020-09-26 14:50:36.053 WARN 19332 --- [ main] com.zaxxer.hikari.util.DriverDataSource :
  25. Registered driver with driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found, trying
  26. direct instantiation.
  27. 2020-09-26 14:50:36.914 INFO 19332 --- [ main] com.zaxxer.hikari.pool.PoolBase
  28. : HikariPool-1 - Driver does not support get/set network timeout for connections. (Feature not
  29. implemented: No details.)
  30. 2020-09-26 14:50:36.920 INFO 19332 --- [ main] com.zaxxer.hikari.HikariDataSource
  31. : HikariPool-1 - Start completed.
  32. 2020-09-26 14:50:37.110 INFO 19332 --- [ main] o.hibernate.jpa.internal.util.LogHelper
  33. : HHH000204: Processing PersistenceUnitInfo [name: default]
  34. 2020-09-26 14:50:37.333 INFO 19332 --- [ main] org.hibernate.Version
  35. : HHH000412: Hibernate ORM core version 5.4.12.Final
  36. 2020-09-26 14:50:37.772 INFO 19332 --- [ main] o.hibernate.annotations.common.Version
  37. : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  38. 2020-09-26 14:50:38.088 INFO 19332 --- [ main] org.hibernate.dialect.Dialect
  39. : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
  40. 2020-09-26 14:50:39.795 WARN 19332 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl
  41. : GenerationTarget encountered exception accepting command : Error executing DDL &quot;drop table wire&quot;
  42. via JDBC Statement
  43. org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL &quot;drop table wire&quot; via
  44. JDBC Statement
  45. at

答案1

得分: 2

这个错误出现在Derby中,是因为默认值被设置为:spring.jpa.hibernate.ddl-auto=create-drop
你需要在你的application.properties文件中将其设置为:spring.jpa.hibernate.ddl-auto=update

英文:

This error appears in Derby due to the default value is set to: spring.jpa.hibernate.ddl-auto=create-drop
You have to set it to: spring.jpa.hibernate.ddl-auto=update in your application.properties file

huangapple
  • 本文由 发表于 2020年9月27日 06:45:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/64083180.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定