Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that the fields cannot be updated when the table is created automatically in springboot

Shulou Source: shulou.com Published: 2022-06-01 12:16:04 10月03日 Update

This article mainly explains how to solve the problem of "automatic table creation in springboot cannot update the field". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn how to solve the problem of "automatic table creation in springboot cannot update fields"!

About automatic table creation, unable to update field problem Configuration in Springboot jpa: database-platform: org.hibernate.dialect.MySQL5InnoDBDialect database: MYSQL show-sql: true properties: hibernate.id.new_generator_mappings: true hibernate.cache.use_second_level_cache: false hibernate.cache.use_query_cache: false hibernate.generate_statistics: false hibernate.hbm2ddl.auto: create #Automatically generate table creation statements hibernate: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl #unhumping hibernate.hbm2ddl.auto: create #auto-generating table creation statements In addition to create configuration, there are several following

create will automatically create tables, all models will create new tables

Create-drop creates a new table, but automatically deletes it as well as SessionFactory.

update will automatically create tables, existing tables cannot be updated, only newly added models will be added to generate tables, so this annotation cannot update the field attributes of existing tables.

validate will verify the Model and database table. If the field attributes are inconsistent, an error none will be reported. The table will not be automatically created. Only the @entity and @Table of the Model will map the database table (the fields may not correspond).

springboot jpa does not automatically create table problem record check whether pom correctly introduced corresponding module org.springframework.boot spring-boot-starter-data-jpa mysql mysql-connector-java Check application file configuration for errors spring: datasource: url: jdbc:mysql://localhost:3306/dbdbd? useUnicode=true&characterEncoding=utf-8&useSSL=false username: * password: * driver-class-name: com.mysql.jdbc.Driver jpa: hibernate: ddl-auto: update database: mysql show-sql: true

Check if the entity class has @Entity annotation

Check the project directory structure to see if entity classes are in the package or subpackage directory where the startup class resides

If not, add @EntityScan("****") annotation to startup class

After checking, all of them are fine, the project starts normally, no error is reported, but the visualization tool navicat does not generate the corresponding table, and it is puzzling and exhausted. Later, holding the idea of trying, in the mysql installation directory bin, the command line to view the database table, found that the corresponding table has actually been successfully established, but navicat is not displayed.

At this point, I believe that everyone has a deeper understanding of "how to solve the problem of automatic table creation in springboot", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Fields updates checks builds data databases annotations directories configurations contents entities attributes automatic generation statements problems projects learning practical deeper consistent Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL MariaDB Redmi macOS