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 use jpaProperties in JPA

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "how to use jpaProperties in JPA", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use jpaProperties in JPA" this article.

JpaProperties for JPA configuration Org.hibernate.cfg.ImprovedNamingStrategy true true update

Where jpaProperties is some of the attributes of jpa.

Org.hibernate.cfg.ImprovedNamingStrategy true true update

There is a property that is

Update

This is a useful setting.

In fact, the function of this hibernate.hbm2ddl.auto parameter is mainly used to automatically create | update | verify the structure of database tables. If it is not a requirement in this area, suggest set value= "none".

Create: each time you load hibernate, you delete the last generated table, and then regenerate the new table according to your model class, even if there are no changes twice, which is an important reason for the loss of database table data.

Create-drop: each time the hibernate is loaded, the table is generated according to the model class, but as soon as sessionFactory is closed, the table is automatically deleted.

Update: the most commonly used attribute, the structure of the table will be automatically established according to the model class when the hibernate is loaded for the first time (provided that the database is established first), and then the table structure will be automatically updated according to the model class when loading hibernate. Even if the table structure has changed, the rows in the table still exist and the previous rows will not be deleted. It is important to note that when deployed to the server, the table structure will not be set up immediately, but only after the application is run for the first time.

Validate: each time you load hibernate, verify that the database table structure is created, and only the tables in the database are compared. No new tables are created, but new values are inserted.

Sping Data Jpa configuration problem spring.jpa.properties.hibernate.hbm2ddl.auto=update

When configuring spring data jpa, if spring.jpa.properties.hibernate.hbm2ddl.auto is set to update, the datasheet structure will be automatically updated. For example, member variables will be added in Entity, and corresponding fields will also be added to the datasheet. But it should be noted that if a member variable is deleted, the corresponding field will not be automatically deleted in the datasheet. If the deleted member variable is set to not null in the datasheet, the corresponding field will not be deleted automatically. An error will be reported when it is run again, as in the following example

Create a new entity class

Import lombok.Data;import javax.persistence.*; @ Entity@Datapublic class Car {@ Id @ Column (name= "id" nullable = false) @ GeneratedValue (strategy = GenerationType.IDENTITY) private Long id; @ Column (nullable = false) private String price; @ Column private String color; @ Column private String brand;}

At this point, you can see that the data table car has been automatically generated in the database, and there are corresponding fields.

At this point, we delete the price in Car, run it again, and we look at the database again.

Found that the price field still exists

The above is all the contents of the article "how to use jpaProperties in JPA". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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