'My SQLDelete annotaion Code is not working
I want to make Soft delete code at Spring Boot... But, @SQLDelete is not working This code is not working on my server. And I have no idea about that.
Entity
@Entity // DB와의 연결을 위하여
@Data // getter setter
// @Where(clause = "is_deleted = false")
@SQLDelete(sql = "UPDATE board SET is_deleted = true WHERE id = ?")
public class Board {
@Id // id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String title;
@Lob
@Column(columnDefinition="TEXT", nullable = false)
private String content;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="user_id", referencedColumnName = "id")
private User user;
@ColumnDefault("false")
private boolean isDeleted;
Service
public void deleteBoard(Long boardId){
boardRepository.deleteById(boardId);
}
Test
@Test
public void 삭제서비스테스트() throws Exception {
//given
User user = new User(1L, "찬", "[email protected]", "picture", Role.GUEST);
userRepository.save(user);
for(int i=0; i<100; i++){
Board board = new Board((long) i, "제목"+i, "내용"+i, user);
boardRepository.save(board);
}
//when
boardService.deleteBoard(4L);
boardService.deleteBoard(15L);
Board board = boardService.findBoard(5L);
Board board2 = boardService.findBoard(15L);
//then
System.out.println("~~~~~~~~~~~~~~~~~~~~~");
System.out.println(board);
System.out.println(board2);
System.out.println("~~~~~~~~~~~~~~~~~~~~~");
}
and result is
~~~~~~~~~~~~~~~~~~~~~
Board(id=5, title=제목5, content=내용5, user=com.board.board.domain.oauth.User@346690d6, isDeleted=false)
null
~~~~~~~~~~~~~~~~~~~~~
I can not understand why it does not work on source.. Can I receive some advice??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
