org.hibernate.tool.schema.spi.CommandAcceptanceException:尝试链



我在课堂上做了一个练习后做了这个项目。我在MySQL工作台中制作了一个名为"fifa"的空方案。

这是错误的开始:


org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table Wedstrijd (id varchar(255) not null auto_increment, dag integer not null, landen tinyblob, uur integer not null, primary key (id)) engine=InnoDB" via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]


Caused by: java.sql.SQLSyntaxErrorException: Incorrect column specifier for column 'id'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:763) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) ~[mysql-connector-java-8.0.29.jar:8.0.29]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54) ~[hibernate-core-5.6.9.Final.jar:5.6.9.Final]
... 34 common frames omitted

这是我的persistencejpacconfig类,这个类与我调用数据的控制器在同一个包中。

package com.spring.WorldCup;

@Configuration
@EnableTransactionManagement
public class PersistenceJPAConfig {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "domain" });
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
@Bean
public DataSource dataSource(){
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
//achter3306/ meot de naam van de databank
dataSource.setUrl("jdbc:mysql://localhost:3306/fifa?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC");
dataSource.setUsername( "root" );
dataSource.setPassword( "root" );
return dataSource;
}

@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(emf);
return transactionManager;
}
@Bean
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
return new PersistenceExceptionTranslationPostProcessor();
}
Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", "create");
//properties.setProperty("hibernate.hbm2ddl.auto", "validate");
return properties;
}
}

注释中的注释导致错误:

@Entity
public class Wedstrijd {
private static final long serialVersionUID = 1L;
@Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
private String id; //unieke sleutel
private String[] landen; //2 landen van de wedstrijd
private int dag; //dag van de wedstrijd
private int uur; //uur van de wedstrijd
public Wedstrijd() {
}

您需要检查应用程序。属性文件详细信息

#Connection url for the database "netgloo_blog"
spring.datasource.url = jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
#Username and password
spring.datasource.username = SYSTEM
spring.datasource.password = SYSTEM
spring.jpa.hibernate.ddl-auto = update

如果所有的细节都是正确的,但你得到相同的异常,那么更新配置为update.

spring.jpa.hibernate.hbm2ddl.auto =更新

相关内容

  • 没有找到相关文章

最新更新