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

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

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

//SpringApplication是一个静态类
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() {

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.

GenerationTarget encountered exception accepting command : Error executing DDL &quot;drop table wire&quot; via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL &quot;drop table wire&quot; via JDBC Statement
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]

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

Pom.xml file

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

&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
     &lt;version&gt;2.2.6.RELEASE&lt;/version&gt;
 &lt;/parent&gt;

 &lt;dependencies&gt;
      &lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
           &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
     &lt;dependency&gt;
	       &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	       &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;			
     &lt;/dependency&gt;
    &lt;dependency&gt;
	      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	      &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;			
     &lt;/dependency&gt;
    &lt;dependency&gt;
	     &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
	     &lt;artifactId&gt;derby&lt;/artifactId&gt;			
      &lt;/dependency&gt;

   &lt;/dependencies&gt;
&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

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

@Entity
public class Wire {

//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 database

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;
}


 }

Main method

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
	
	//SpringApplication is a static class
	SpringApplication.run(WiresAPI.class, args);

  }

 }

Repository file

package io.wiresapi.springbootstarter.Wires.SendWires;

import org.springframework.data.repository.CrudRepository;

//Spring data JPA has already an interface for all CRUM operations

 public interface WireRepository extends CrudRepository&lt;Wire,String&gt;{


}

Controller file

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;

//We map an incoming request from the client to an appropriate method.

//Get all wires URI
@RequestMapping(&quot;/Wires&quot;)
public List&lt;Wire&gt; TotalWiresSent() {
	
	return aWireService.getAllWires();
}

}

Console

:: Spring Boot ::        (v2.2.6.RELEASE)

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

  org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL &quot;drop table wire&quot; via 
  JDBC Statement
   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:

确定