Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report