hibernate If used directly in
Session.update(Object o);
All the fields in this table will be updated .

such as :

public class Teacher Test {
@Test
public void update(){
Session session = HibernateUitl.getSessionFactory().getCurrentSession();
session.beginTransaction();
Teacher t = (Teacher) session.get(Teacher.class,3);
t.setName("yangtb2");
session.update(t);
session.getTransaction().commit();
}
}

Hibernate Executive SQL sentence :
Code

Hibernate:
UPDATE
Teacher
SET
age=?,
birthday=?,
name=?,
title=?
WHERE
id=?

We just changed Name attribute , and Hibernate Of sql sentence Change all the fields once .
So if we have fields that are text types , This type stores thousands of , Tens of thousands of words , It's inefficient .
So how can we just change the fields we update ?
There are three ways :

1.XML Set in property label update = “false” , as follows : We set up age This property does not change during the change

stay Annotation in In attributes GET Method plus @Column(updatable=false)

@Column(updatable=false)
public int getAge() {
return age;
}

We're executing Update The method will find ,age attribute Will not be changed

Hibernate: 
UPDATE
Teacher 
SET
birthday=?,
name=?,
title=? 
WHERE
id=?

shortcoming : inflexible ····

2. The first 2 Methods ·· Use XML Medium dynamic-update="true"

<classname="com.sccin.entity.Student"table="student"dynamic-update="true"/>

OK, So you don't have to set it on the field .
But this approach is Annotation There is no

3. The third way : Use HQL sentence ( flexible , convenient )

Use HQL Statement to modify data
public void update(){
Session session = HibernateUitl.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("update Teacher t set t.name = 'yangtianb' where id = 3");
query.executeUpdate();
session.getTransaction().commit();
}

Hibernate Executive SQL sentence :
Hibernate:
update
Teacher
set
name='yangtianb'
where
id=3

This only updates the fields we updated ·····

hibernate update Update only part of the fields 3 Methods ( Actually, I just want to talk about the second one ) More articles about

  1. hibernate update Update only part of the fields 3 Methods ( Reprint )

    hibernate If used directly in Session.update(Object o); All the fields in this table will be updated . such as : public class Teacher Test { @Test p ...

  2. hibernate update Partial update

    hibernate update Hibernate If used directly in Session.update(Object o); All the fields in this table will be updated . such as : view plaincopy to ...

  3. EF Update only some fields

    /// Update only storedAddress In the data DefaultAddress Field , Updated to false /// Change the default address to a non default address /// </summary> /// <par ...

  4. 【mybatis】 mybatis stay mysql to update update operation The update time field is in the format of month, year, day, hour, minute and second Update to current time

    The sample code is as follows : update goods_msg SET create_date = DATE_FORMAT(NOW(),'%Y-%m-%d %H:%m:%s') WHERE uid = '6183b ...

  5. Hibernate Update several types of certain fields update Method

    Hibernate If used directly in Session.update(Object o); All the fields in this table will be updated . such as : public class TeacherTest { @Test pu ...

  6. Hibernate Update some fields

    update The statement is in Hibernate Of Configuration It's generated when I'm in the hospital , Can't change dynamically . Why? update All the attributes are together when you're in the game update, Instead of just updating the change field , In fact, this is a problem worthy of discussion ...

  7. mybatis Way of learning ---- Compare the efficiency of two methods of batch updating data

    original text :https://blog.csdn.net/xu1916659422/article/details/77971696/ In the previous section, we discussed batch data addition , This section discusses the efficiency of two methods of writing batch update data . Implementer ...

  8. ASP.Net Several ways to update the page output cache

    ASP.Net The built-in caching mechanism plays an important role in improving page performance , On the other hand , The use of cache will also cause the delay of information update . How to quickly update cache data , Sometimes it's a problem for programmers . According to my experience , The following methods are summarized , Summed up ...

  9. Hibernate Update the implementation of some fields

    stay Hibernate in , Sometimes we just need to update some fields , If you use update() Method , All fields will be updated , For no set Field of , It will be set to NULL, If there are non empty fields in these fields, an error will be reported . solution ...

Random recommendation

  1. JVM Heap memory setup and testing

    1. Java Virtual machine memory structure Divide the new generation and the old generation , This only allocates memory in the new generation , This simplifies the allocation of new objects . In addition, the new generation and the old generation use different GC Algorithm , It can more effectively clean up objects that are no longer needed . As can be seen from the above figure ,JVM Memory by yo ...

  2. wamp2.5 Virtual site establishment

    1. D:\wamp\bin\apache\Apache2.2.21\conf Open in directory httpd.conf Modify the following places .( Software installed in D disc ) (1)178 That's ok DocumentRoot " ...

  3. Java Multithread synchronization class in CountDownLatch

    In multithreaded development , We often encounter the operation that we want a group of threads to perform after completion ,java Provides a multithread synchronization helper class , This kind of requirement can be fulfilled : Class : Among them, the construction method :CountDownLatch(int count) ...

  4. PAT (Basic Level) Practice ( chinese )1001 It's not worth killing (3n+1) guess

    1001  It's not worth killing (3n+1) guess Karaz (Callatz) guess : For any positive integer  n, If it's even , Then cut it in half : If it's an odd number , Then put the  (3n+1)  Cut off half . I've been chopping it over and over again , Finally ...

  5. Python Homework on the second day of the course

      One . Statistical string format requirement : # 1. Count the number of strings in the tuple , Tips : isinstance() # data : t1 = (1, 2, '3', '4', 5, '6') # result : 3 Code ...

  6. Multithreading development II NSOperation

    The effect is as follows : ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UITableViewControll ...

  7. R Language reading Hive Data sheet

    R adopt RJDBC Package connection Hive at present Hive The cluster can be accessed through the springboard machine HiveServer, take Hive Read batch data in R Environmental Science , And carry on the following model and algorithm operation . 1. After logging in to the springboard machine, you need to first Linux ...

  8. javascript The optimization of conditional judgment statement in classification : JavaScript 2015-06-07 09:54 832 Human reading Comment on (2) Collection

    No matter what program you write , We usually use conditional sentences , Such as :if...else... switch Such a statement , To judge the condition . Here's a piece of code : function abc(test){ if (test == 1) ...

  9. android Interprocess communication messenger What is it? binder Follow aidl difference intent Interprocess Communications ? android Message mechanism Interprocess android Interprocess It can be used handler Well messenger And handler Mechanism messenger Mechanism Is it right? Namely handler Mechanism or , Is it Message mechanism android messenge

    Han Meng Feisha   Han Yafei  313134555@qq.com  yue31313  han_meng_fei_sha messenger What is it? binder Follow aidl difference intent Interprocess Communications ...

  10. git log Exit method

    Press... In English Q