@Transient annotation, @ org.springframework.data.annotation.Transient annotation, transient keyword, and password saving

I am currently studying the Spring framework, mainly focusing on this security module. I looked at several guides in connection with registration and registration. I saw this common use of the transient or @Transient keyword in the password field in the User class .

My dummy application uses Spring Boot + Spring MVC + Spring Security + MySQL.

I know that

The Java transient keyword is used to indicate that the field should not be serialized.

JPA @Transient annotation ...

... indicates that the property or field is not constant . It is used to annotate a property or field of an entity class, a displayed superclass, or a nested class.

and org.springframework.data.annotation @Transient of annotation .. .

Marks the transition field for the display structure. Thus, the property will not be saved and will not be additionally checked by the display framework.

In my MySQL db, I have my spring_demo schema that has 3 tables:

+-----------------------+
| Tables_in_spring_demo |
+-----------------------+
| role                  |
| user                  |
| user_role             |
+-----------------------+

When I use the transient keyword in the password field of the int class User password, it will not be stored in MySQL db. (example: test01)

mysql> select * from user;
+----+--------+------------------+----------+
| id | active | email            | username |
+----+--------+------------------+----------+
|  1 |      1 | test01@gmail.com | test01   |
+----+--------+------------------+----------+
1 row in set (0,00 sec)

javax.persistence @Transient User, MySQL db. (: test02)

... org.springframework.data.annotation @Transient User, MySQL db. (: test03) ?

mysql> select * from user;
+----+--------+------------------+----------+--------------------------------------------------------------+
| id | active | email            | username | password                                                     |
+----+--------+------------------+----------+--------------------------------------------------------------+
|  1 |      1 | test02@gmail.com | test02   |                                                              |
|  2 |      1 | test03@gmail.com | test03   | $2a$10$UbvmdhfcKxSNr/I4CjOLtOkKGX/j4/xQfFrv3FizxwEVk6D9sAoO  |
+----+--------+------------------+----------+--------------------------------------------------------------+
2 rows in set (0,00 sec)

: @Transient spring.data, . ? @Transient ?

!

+6
1

Spring Framework Mapping Framework . , , Spring java server (-, ) JSON.

@Entity
public class User {

@Id
private long id;

@Column(name = "username")
private String username;

@Column(name = "email")
private String email;

@Column(name = "password")
private String password;

}

, java JSON, (, jackson: com.fasterxml.jackson.databind.ObjectMapper), .

JSON, , user 2 JSON:

{
   "id": 2,
   "email": "test03@gmail.com",
   "username": "test03",
   "password": "$2a$10$UbvmdhfcKxSNr/I4CjOLtOkKGX/j4/xQfFrv3FizxwEVk6D9sAoO"
}

, :

@org.springframework.data.annotation.Transient
@Column(name = "password")
private String password;

Mapping Framwork, JSON user 2:

{
   "id": 2,
   "email": "test03@gmail.com",
   "username": "test03",
}

, JSON- . @org.springframework.data.annotation.Transient Spring, Map Mapper Java Object JSON.

, , , @org.springframework.data.annotation.Transient - , JPA.

, :

transient ( , , db)
javax.persistence.Transient JPA DB @org.springframework.data.annotation.Transient ObjectMapping Framework, Spring

+7

Source: https://habr.com/ru/post/1015688/


All Articles