221223 TIL Suspend User and unsuspend a user account

William Parker·2022년 12월 23일

Today, we implemented a method to suspend and unsuspend a user account.

Problem
An error occurred during bi-directional mapping.

Error Occurred:

Error creating bean with name 'entityManagerFactory' defined in class path resource

  // before editing
  @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
  private List<SupportTicket> supportTickets;
  // after editing
  @OneToMany(mappedBy = "complainant", cascade = CascadeType.ALL)
  private List<SupportTicket> supportTickets;
  
  @ManyToOne
  @JoinColumn(name = "user_id")
  private User complainant;

solved and found out
Reason When setting mappedby, it must be the same as the field name in the table that relates the contents. Also
List findAllByComplainantId(Long id);
Knowing how to get and use values ​​inside other objects.


Problem

It is not automatically saved to the database.

// before editing
  public boolean dev_UpdateUser(JWTSessionContainer container, UpdateUserInformationRequest req) {
      User user = uRepository.findByEmail(container.getEmail());
      user.Update(req);
		uRepository.save(user);
      return true;
 
// after editing
 @Transactional 
  public boolean dev_UpdateUser(JWTSessionContainer container, UpdateUserInformationRequest req) {
      User user = uRepository.findByEmail(container.getEmail());
      user.Update(req);
      return true;
  }

solved and found out

@Transactional is omitted from the update method, the result value is not automatically saved even if it succeeds. Know how to use that annotation.

@Transactional features
-Atomicity
Operations executed within a transaction are processed as a unit
all succeed or all fail
-Consistency
Transactions maintain consistent database state
-Isolation
Isolate concurrently executing transactions from affecting each other
-Durability
The result is always stored when a transaction is successfully completed.


Korean Version.
-원자성(Atomicity)
한 트랜잭션 내에서 실행한 작업들은 하나의 단위로 처리
모두 성공하거나 모두 실패
-일관성(Consistency)
트랜잭션은 일관성 있는 데이터베이스 상태를 유지
-격리성(Isolation)
동시에 실행되는 트랜잭션들이 서로 영향을 미치지 않도록 격리
-영속성(Durability)
트랜잭션을 성공적으로 마치면 결과가 항상 저장

profile
Developer who does not give up and keeps on going.

0개의 댓글