- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在尝试创建上述实体时,我收到 CommandAcceptanceException 并且无法在数据库中创建表,请告诉我如何修复它。
application.properties 文件
spring.datasource.url= jdbc:mysql://localhost:3307/mapping
spring.datasource.username=root
spring.datasource.password=admin
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
@Entity
@Table(name="BOOKS")
public class Book {
@Id
@Column(name="bookId")
private Long id;
@Column(name="TITLE")
private String title;
@Column(name="AUTHOR")
private String author;
public Book(Long id, String title, String author) {
super();
this.id = id;
this.title = title;
this.author = author;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Book() {
super();
// TODO Auto-generated constructor stub
}
}
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'org.springframework.hib'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
2020-01-09 21:52:36.380 INFO 14108 --- [ main] com.learn.hib.LearnHibernateApplication : Starting LearnHibernateApplication on LAPTOP-B759SS03 with PID 14108 (E:\learn-space\learn-hibernate\bin\main started by Lenovo in E:\learn-space\learn-hibernate)
2020-01-09 21:52:36.380 INFO 14108 --- [ main] com.learn.hib.LearnHibernateApplication : No active profile set, falling back to default profiles: default
2020-01-09 21:52:36.974 INFO 14108 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-01-09 21:52:37.037 INFO 14108 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 46ms. Found 1 JPA repository interfaces.
2020-01-09 21:52:37.302 INFO 14108 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-01-09 21:52:37.521 INFO 14108 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-01-09 21:52:37.535 INFO 14108 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-09 21:52:37.535 INFO 14108 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-01-09 21:52:37.644 INFO 14108 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-01-09 21:52:37.644 INFO 14108 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1217 ms
2020-01-09 21:52:37.816 INFO 14108 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-01-09 21:52:37.878 INFO 14108 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.4.9.Final}
2020-01-09 21:52:38.003 INFO 14108 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-01-09 21:52:38.097 INFO 14108 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-01-09 21:52:39.206 INFO 14108 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-01-09 21:52:39.216 INFO 14108 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
Hibernate: create table books (book_id bigint not null, author varchar(255), title varchar(255), primary key (book_id)) type=InnoDB
2020-01-09 21:52:39.935 WARN 14108 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "create table books (book_id bigint not null, author varchar(255), title varchar(255), primary key (book_id)) type=InnoDB" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table books (book_id bigint not null, author varchar(255), title varchar(255), primary key (book_id)) type=InnoDB" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:559) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:504) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:277) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:207) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:114) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:184) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:73) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:320) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1237) [hibernate-core-5.4.9.Final.jar:5.4.9.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) [spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) [spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) [spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1108) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at com.learn.hib.LearnHibernateApplication.main(LearnHibernateApplication.java:10) ~[main/:na]
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 1
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.4.1.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.4.1.jar:na]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.4.9.Final.jar:5.4.9.Final]
... 34 common frames omitted
2020-01-09 21:52:39.950 INFO 14108 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-01-09 21:52:39.950 INFO 14108 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-01-09 21:52:40.028 WARN 14108 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-01-09 21:52:40.528 INFO 14108 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-01-09 21:52:40.837 INFO 14108 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-01-09 21:52:40.837 INFO 14108 --- [ main] com.learn.hib.LearnHibernateApplication : Started LearnHibernateApplication in 4.831 seconds (JVM running for 6.101)
最佳答案
你只需要改变spring.jpa.hibernate.ddl-auto
属性(property)到update
或 create
和spring.jpa.properties.hibernate.dialect
至 org.hibernate.dialect.MySQL5InnoDBDialect
(正如 Patel Romil 所建议的),一切都会正常进行。create-drop
通常用于测试目的,当您想在应用程序启动时创建表时,在测试中执行一些数据库事务,然后在测试用例清理时删除表。测试用例执行完成后,该表将不存在于数据库中。
现在来到spring.jpa.properties.hibernate.dialect
, 使用 org.hibernate.dialect.MySQL5InnoDBDialect
而不是 org.hibernate.dialect.MySQLInnoDBDialect
使 Hibernate 附加 engine=InnoDB
而不是 type=InnoDB
到查询,因此您的查询在语法上是正确的(仅供引用,type= InnoDB
在 MySQL 5.0 中已弃用,并在 My SQL 5.1 中删除)
更多详情spring.jpa.hibernate.ddl-auto
属性及其值(value),这是一个可接受的答案 How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?
关于hibernate - org.hibernate.tool.schema.spi.CommandAcceptanceException : Error executing DDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59668487/
有时我一直在努力理解为什么在尝试创建航路点任务时任务管理器会收到错误“无法执行执行”。我附上了我正在使用的工作流程,如果您能看一下,我将不胜感激。 1.Initialize FlightControl
我正在 Python 中使用 SQLAlchemy 核心,并且我已多次阅读文档,但仍然需要有关 engine.execute() 的说明。与 connection.execute() . 据我了解,e
在我的 Zend 框架项目中,我想检查是否设置了 cookie。如果是这种情况,我想使用 cookie 内容登录用户。 由于我必须在调用任何 Controller 之前执行此自动登录,因此我尝试将其放
我正在尝试为我创建的 2 个选择语句的 UNION 创建一个 View 。 UNION 在单独执行时工作正常 但问题是当我将它作为 View 执行时,只有 UNION 的第一部分被执行。 我正在使用的
下面我写了一个简单的例子来演示我遇到的问题。执行代码后,我得到一个 cygwin 异常 7200。我环顾四周并尝试了一些事情,但没有解决。有人可以解释为什么我得到它,我该如何解决?感谢您抽出宝贵时间,
从池中获取连接然后在连接上调用 execute 而不是直接在池对象上调用 execute 的用例是什么? 在 Pool 的文档中类,显示此示例: con = await pool.acquire()
我正在尝试通过 SQL 将变量中的 2 个值插入表中,代码完成时没有错误,但条目未显示在表中。 我尝试在即时窗口中执行代码,但这给了我一个关于括号的错误(我真的不知道如何在那里正确输入提示),所以我将
我对广播接收器有点困惑。我有一个广播接收器,它在 TIME_SET 和 TIMEZONE_CHANGED 操作时触发(代码在下面给出)。我想知道的是,当 TIME_SET 和 TIMEZONE_CHA
我必须与需要随每个请求发送访问 token 的外部服务集成。访问 token 的到期时间很短(只有几个小时)。我决定以乐观的方式使用访问 token 。我将使用当前 token 调用外部服务。如果出现
如果我在 swift 中运行以下代码,步骤 1.、2.、3. 和 4. 是否始终按此顺序执行(它们应该如此),或者如果循环存在异步执行的风险,排序等,花费的时间比预期的要长? // 1. fo
我在我的 C++ 应用程序中看到访问冲突错误。在发生违规并使用 !analyze 时将 windbg 附加到进程时,我发现访问违规是由于试图执行不可执行的地址。我知道导致此问题的正在执行的地址。什么可
在使用 Ubuntu 大约一年之后,这对我来说是第一次。 我接手了一个跟踪维修的汽车服务项目。我可以看到每个文件的完整源代码,但是有一个没有扩展名的文件,但在 Ubuntu 中,属性显示为可执行文件(
什么是 LinqPad“自动跟踪执行”和“跳转到执行点”?如何使用它们,如果你能给出一个详细的例子将不胜感激。 最佳答案 这不是一个详细的示例,但它说明了该功能。如果你有一个像 "1".Dump()
我使用 Q.js 来实现 promise 。在下面的代码中,每个方法都会进行 ajax 调用,然后返回一个 Promise。一切都按预期进行,每个方法在下一个方法开始之前执行并完成: function
我有一个类,它实现了 Runnable接口(interface),并且是一个一旦启动就会无限期运行的任务(长时间运行的线程)。 public class LongRunningTask impleme
PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: 无效的参数数量:绑定(bind)变量的数量与标记数量不匹配 我收到此错
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
想要为执行的每个 linux 命令添加 aspect:executionTime 有什么方法可以添加默认方面环境,以便必须为执行的 linux 命令获取 executionTime 最佳答案 根据 m
我正在尝试安装一个名为 MFOC 的工具.我按照其网站中提到的说明进行操作,如下所示: ebrahim@ubuntu:~$ cd Desktop/mfoc-master/ ebrahim@ubuntu
我刚开始使用 numba 来提高我的程序的性能。我已经减少了我将要呈现的情况 import numba as nb import numpy as np from time import time d
我是一名优秀的程序员,十分优秀!